Go language environment installation here will not do too much introduction, is to download and install.

Go official website: golang.org/dl

Go official mirror site: golang.google.cn/dl

Go Module

In the early days, all of the third-party libraries that Go relied on were placed under the directory GOPATH. This leads to project development is not very convenient. So we directly use a nice tool called Go Module to help us realize that we can create Go projects in any directory.

Go Module is an official version management tool released after Go1.11 and will be the default dependency management tool for the Go language starting with Go1.13.

With the Go Module, we start it first. It has three optional values: off, on, and auto. The default is auto

windows

set GO111MODULE=on
Copy the code

mac

export GO111MODULE=on
Copy the code

And then you type go env to see that

That will do

Both the project

If you need to enable an existing project, follow these steps:

  1. Run go mod init in the project directory to generate a go.mod file.
  2. Perform go get to find and record the dependencies for the current project, while generating the go.sum record for the version and hash of each dependency library.

The new project

For a newly created project, we can follow these steps in the project folder:

  1. Create a go.mod file in the current project folder by executing the go mod init project name command.

  2. Manually edit the Require dependency in go.mod or perform go get to automatically discover and maintain the dependency

GOPROXY

After Go1.11, set the GOPROXY command to:

export GOPROXY=https://goproxy.cn
Copy the code

After Go1.13, the default value of GOPROXY is proxy.golang.org. Therefore, GOPROXY is set because it is inaccessible in China

go env -w GOPROXY=https://goproxy.cn,direct
Copy the code

Then the Go env is also viewable

Now that you have the basic configuration, you can start writing code.