Home > Backend Development > Golang > Do you know why using GOPATH is no longer recommended and how to use Go Modules

Do you know why using GOPATH is no longer recommended and how to use Go Modules

藏色散人
Release: 2021-01-11 14:41:44
forward
3138 people have browsed it

The following tutorial column will introduce to you why it is no longer recommended to use GOPATH and how to use Go Modules. I hope it will be helpful to friends in need! Reason: With Go Modules

History:

An environment variable used to tell GO when compiling the project Where to read source files

Restriction rules:

Requires the project to be written under GOPATH
  • Needs to create a directory based on the actual URL path of the project. For example, github.com/foo/bar => $GOPATH/src/github.com/foo/bar
    • There is no built-in version tracking for extension packages
  • With Go Modules

One line of command to migrate old projects

Only affects the development environment, not the production environment
  • Compatible with GOPATH, you can still use GOPATH
  • to Go Modules

version requirements>=1.11## according to your personal preferences.

  • #go mod init

    Command initialization, such as:
mkdir myProject/
cd myProject
go mod init github.com/myGithubName/myProject
Copy after login
  • GOPATH project migration, such as:

    mv ~/go/src/github.com/myGithubName/myProject ~/anywhere_else/
    cd ~/anywhere_else/myProject
    go mod init github.com/myGithubName/myProject
    Copy after login
  • The above content is compiled from: https://medium.com/@vingarcia00/golang-why-not-use-the-gopath-87521259663a
  • In addition, if you use Goland IDE, open Settings and go to Go -> Go Modules (vgo), check Enable Go Modules (vgo) Integration, otherwise the extension package will not be recognized.

                                                                                                                                                          

    go language

    column!

  • The above is the detailed content of Do you know why using GOPATH is no longer recommended and how to use Go Modules. For more information, please follow other related articles on the PHP Chinese website!

    Related labels:
    go
    source:learnku.com
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template