go module package management study notes

go module warehouse agent (Ali cloud): GOPROXY = https: //mirrors.aliyun.com/goproxy/

1. Set the module support

go 1.11 has experimental support modules, most of the sub-command knows how to deal with a module, such as  run build install get list mod sub-command, third-party tools may support later. To go 1.12 will delete  GOPATH support, go get command module will become only get, not so direct access to a bare package as they are now.

Environment variables can be used  GO111MODULE to enable or disable the module support, it has three possible values: off, , on, autodefault is  auto.

  • GO111MODULE=off No module support, go look for the package from GOPATH and vendor folders.
  • GO111MODULE=on Module supports, go ignores GOPATH and vendor folders, based only  go.mod download the dependencies.
  • GO111MODULE=auto In the  $GOPATH/src outside and the root directory has  go.mod a file open module supports.

When using the module, GOPATH it is meaningless, but it still will download dependencies are stored in  $GOPATH/pkg/mod the will the  go install results be placed  $GOPATH/bin in.

 

2. initialization module

go mod init [module name]

go mod init test command Try our run, directory swells into a go.mod file, as follows:

module test

go 1.12

For example, I want to install beego framework, run the command: go get github.com/astaxie/beego
content of the document has changed:

module test

go 1.12

require (
    github.com/astaxie/beego v1.12.0 // indirect
    github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect
)

Description go get the file had an impact, the installation package is introduced into the go.mod file.

Other commands Description:

go mod download: install the mod module to the local cache
go mod vendor: vendor version of the solution will depend copied to the vendor below.

go mod tidy: remove unused modules, and add the missing modules.

go mod verify: Verify that all modules are correct.

 

It had previously been down to under $ GOPATH / src longer refer to the module, feeling a bit OUT ah, this method is much better ...

Guess you like

Origin www.cnblogs.com/tudou1223/p/11447675.html