What are the four steps to learning any programming language

  • Development Tool Installation
  • IDE installation
  • Set the dependency/package domestic mirror
  • Project build tools to manage dependencies/packages

I. Installation of Golang development tool

Golang.org/ github.com/golang/go github docscn.studygolang.com/ golang Chinese website

Goland IDE installation

www.jetbrains.com/zh-cn/go/

3. Set the dependency/package domestic mirror

Common mirror address:

Aliyun: HTTPS://mirrors.aliyun.com/goproxyMicrosoft: HTTPS://goproxy.ioSeven Niuyun: HTTPS://goproxy.cn
 
GoCenter: https://gocenter.io
Copy the code

Modify theGOPATHThe path

Default path %USERPROFILE%\go on Windows $HOME/go on mac&linux

What I demonstrate here is setting the GOPATH path to D:\ GOPATH

D:\ Gopath is used to store third-party dependencies downloaded by go Mod D:\GolandProjects is used to store projects

// Always enable go Modules
go env -w GO111MODULE=on
// Set ali cloud mirror
go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/
/ / set gopath
go env -w GOPATH=D:\gopath
Copy the code

willGOPATHAdd to environment variable

Gopath Settings in Goland

Iv. Project building tools, managing dependencies/packages

Advantages of using go Mod to build projects

  1. Automatically downloads dependency packages
  2. Projects don’t have to be in GOPATH/ SRC anymore
  3. A go.mod file is generated within the project, listing package dependencies
  4. All third party packages will specify the exact version number
  5. For packages that have been moved, replace can be declared without changing the code

Refer to the article

GOROOT, GOPATH, Go with the relations between Modules – introduce blog.csdn.net/y1534414425…

1, ingo.modEdit the

Go. Mod can write the following keywords:

  • module

Define module paths

  • go

Define the GO language version

  • require

Specify the dependency suite, default is the latest version, you can specify the version number

  • exclude

Exclude the suite and its versions

  • replace

Use a different kit version and replace the original kit version

  • annotations

// A single line of comments /* multiple lines of comments */ Indirect represents a dependency package that is indirectly imported

2. Command linego getaddress

As long as it’s ongo modulesFunction,go getI wouldn’t be in the same placeGOPATH/srcThe next place kit file will be placed insteadGOPATH/pkg/modInside, andgo.modI’ll write introductions so I don’t have to use themgo mod downloadThe instruction.