No matter what programming language you learn, the four steps you will experience at the beginning
- Development tool installation
- IDE installation
- Set dependency/package domestic mirror
- Project build tool, manage dependencies/packages
1. Golang development tool installation
https://golang.org/ official website (requires their own means)
https://github.com/golang/go github address
http://docscn.studygolang.com/ golang中文网
Two, Goland IDE installation
https://www.jetbrains.com/zh-cn/go/
Three, set dependency/package domestic mirror
Common mirror address:
阿里云: https://mirrors.aliyun.com/goproxy
微软: https://goproxy.io
七牛云: https://goproxy.cn
GoCenter: https://gocenter.io
Modify GOPATH
path
windows
On the default path %USERPROFILE%\go
mac&linux
On the default path$HOME/go
What I demonstrate here is to set the GOPATH
path toD:\gopath
D:\gopath
Used to store go mod
downloaded third-party dependency packages
D:\GolandProjects
Used to store projects
// 始终开启go modules
go env -w GO111MODULE=on
// 设置阿里云镜像
go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/
// 设置gopath
go env -w GOPATH=D:\gopath
Will be GOPATH
added to environment variables
Gopath settings in Goland
Four, project construction tools, manage dependencies/packages
Use go mod
method to build project advantages
- Automatically download dependencies
- The project does not have to be placed in GOPATH/src
- A go.mod file will be generated in the project, listing package dependencies
- All third-party packages will accurately specify the version number
- For packages that have been transferred, you can use the replace statement to replace, no need to change the code
Reference article
Relations GOROOT, GOPATH, Go-Modules- three introduced
https://blog.csdn.net/y1534414425/article/details/108767310
1, in the go.mod
edit
Go.mod can write the following keywords:
- module
defines the module path - go
definition go language version - require
specifies the dependent package, the default is the latest version, you can specify the version number - exclude
exclude the package and its version - replace
use a different package version and replace the original package version - Annotation
// Single-line annotation
/* Multi-line annotation*/
indirect represents dependent packages that are indirectly imported
2, the command-line go get
address
As long as there are open go modules
feature, go get
it will not be the same as in the previous GOPATH/src
case files placed kit, but will be placed GOPATH/pkg/mod
there, and go.mod
will write the introduction, so do not use it go mod download
commanded.