Go Module Concise tutorial (Go language-dependent package management tool)

Source: Internet
Author: User
The Go module is a dependent package management tool for the go language.

Use of the Go module

1, Go1.11 and later version to use.
2, Go1.11 need to set the environment variable Go111module to ON (new feature switch, according to the Go Language Convention, MoD for the first time in the go1.11 version of the use, go1.12 and later version of this setting should not be used).

MoD is a shorthand for module English modules.

List some of the commonly used command lines:

    • go help modView Help.
    • go mod init <项目模块名称>Initializes the module and generates the file at the root of the project go.mod . Parameters are <项目模块名称> required, but if your project has not yet been written, this parameter will initialize the module quickly. If you previously used other dependency management tools (such as dep,glide, etc.), the MoD would automatically take over the original dependency.
    • go mod tidyThe dependencies are handled according to the Go.mod file.
    • go mod vendorCopy the dependent package to the vendor directory under the project. It is recommended that some use of the wall bag can be handled so that the user quickly use the command to go build -mod=vendor compile.
    • go list -m allDisplays dependencies.
    • go mod download <path@version>Download dependencies. The parameter <path@version> is not required, path is the package, and version is the package.
    • Other commands can be go help mod viewed through.

Other than that:
The Go.mod file is a text file that you can edit manually.
The download files and information for the Go Module version control are stored in the Gopath pkg/mod folder.
Using the Go module, the source code is not necessarily in the gopath.

Using the example

Go.mod file

module github.com/wuyumin/easydocrequire (    github.com/BurntSushi/toml v0.3.0    github.com/mostafah/fsync v0.0.0-20151120150823-6c37e2827238    github.com/russross/blackfriday v1.5.1)

GIT recommends

The Go.mod file must be submitted to the GIT repository, but the Go.sum file can not be submitted to the Git repository (git ignores the file. Set it in Gitignore).

Resources

    • Semantic version (Chinese) https://semver.org/lang/zh-CN/
    • Go Module Official document (English) https://golang.google.cn/cmd/...

Welcome to fix

此篇文章最新的更改都会在GitHub上进行。
The original link on GitHub
Https://github.com/wuyumin/tu ...
Welcome to the Star Project on GitHub or through issues to provide suggestions for amendments.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.