download

Download – The Go Programming Language (golang.org)

Windows installation

Download the file to install

The latest stable version is GO1.15, Windows download address: GO1.15.5

  1. Open the downloaded file, and then next, next, the default installation in C:\Go directory, if necessary can be installed when the change, you can also reopen the command program installation.

  2. To confirm that Go is installed, run the CMD command to open the command window and enter the following command:

    $ go version
    Copy the code

Ii. Use scoop installation

Scoop is a community-provided Windows package management tool solution that installs Windows applications using the command line

Open the command line and enter the following command to search for go:

$ scoop search go
Copy the code

Enter the following command to install:

$ scoop install go	
Copy the code

After the installation is complete, enter Go Version to view the current installed version, or use scoop Install [email protected] to install the specified version, and scoop uninstall Go to delete the installation package

Linux installation

  1. Download the file and decompress it to the /usr/local directory. Create a go directory tree in the /usr/local directory

    For example, run the following command as root or as sudo:

    Tar -c /usr/local-xzf go1.15.5.linux-amd64.tar.gzCopy the code
  2. Add the /usr/local/go/bin directory to the PATH environment variable

    You can add the following command to $HOME/. Profile or /etc/profile (for all system users) to complete the addition of environment variables:

    Add the /usr/local/go/bin directory to the PATH environment variableCopy the code
  3. After the installation is complete, enter Go version to view the current version

Set up the Go Modules and proxy

Go Modules is the Go language dependency management solution

Mod file field content

Go.mod is the most important file required for a Go Moduels-enabled project. It describes the meta information for the current project (that is, the current module), and each line begins with a verb, which currently has the following five verbs:

  • Module: Defines the module path for the current project.
  • Go: Used to set the expected GO version.
  • Require: Used to set a specific module version.
  • Exclude: Used to exclude a particular module version from use.
  • Replace: Used to replace one module version with another.

Open the go. The mod

  1. Open Go Modules:go env -w GO111MODULE=on.
  2. Set GOPROXY:go env -w GOPROXY=https://goproxy.cn,direct# is required in China because its default value is blocked.
  3. Execute in the root directory of your projectgo mod init <OPTIONAL_MODULE_PATH>To generate the go.mod file.

Go modules Common command

  1. Use Go Help module-get and Go Help Gopath -get to understand the go Get behavior in the go Modules enabled and not enabled states respectively

  2. Pull new dependencies with Go Get

    • Pull the latest version (tag is preferred) :go get golang.org/x/text@latest
    • pullmasterBranch’s latest COMMIT:go get golang.org/x/text@master
    • Pull commit with tag v0.3.2:Go get golang.org/x/[email protected]
    • Pull commit with hash 342b231, which will be converted to v0.3.2:go get golang.org/x/text@342b2e
    • withgo get -uUpdate existing dependencies
    • withgo mod downloadDownload all dependencies specified in the go.mod file
    • withgo mod tidySort out existing dependencies
    • withgo mod graphLook at existing dependency structures
    • withgo mod initGenerate go.mod files (the only subcommand in Go 1.13 that can generate go.mod files)
  3. Edit the go.mod file with Go Mod Edit

  4. Export all existing dependencies with Go Mod Vendor (actually Go Modules are de-emphasizing the concept of vendor)

  5. Use Go Mod Verify to verify if a module has been tampered with