First, set the environment variable
Second, go modules enable the feature and set the proxy
supplement:
GO111MODULE
There are three values: on, off, auto
GO111MODULE=off
, Go command line support module does not function, look for dependencies manner will use the old version of the kind referred to by their vendor directory or GOPATH mode.GO111MODULE=on
, Go command line using the modules, but that will not go GOPATH Find directory.GO111MODULE=auto
The default value, go to the command line will decide whether to enable the function module according to the current directory.
Enabled the modules, dependencies mounting position at $ GOPATH / pkg directory; go mod provides the following command:
Three, go mod command Management Pack
- In any path GOPATH that the new project directory, eg: GOPATH directory D: GoCode; project directory D: Project / testProject
- Into the project directory, create a directory bin, src / main, into the src directory; Note: Here the directory are free.
- Use the command: go mod init main, this case generates a go.mod file; NOTE: go mod init command later be able to keep the file name (with the suffix). After go.mod file is created, its contents will be go toolchain full control. go toolchain will be in the various types of command execution, such go get, go build, go mod and other modifications and maintenance go.mod file.
- Into the main directory, create main.go file, write the code:
package main import ( "net/http" "github.com/labstack/echo" ) func main() { e := echo.New() e.GET("/", func(c echo.Context) error { return c.String(http.StatusOK, "Hello, World!") }) e.Logger.Fatal(e.Start(":1323")) }
- Use the command: go run main.go, the result of normal operation as follows:
- Principles go module installation package is to first pull the latest release tag, if no tag is pulling the latest commit. go go.sum will automatically generate a file to record the dependency tree. go.mod document reads as follows
go.moudles official description: https://github.com/golang/go/wiki/Modules
go.mod offers module
, require
, replace
and exclude
four command
module
Statement specifies the package name (path)require
Statement specifies dependencies modulereplace
Statements can replace the module dependenciesexclude
Statement can ignore dependencies module