When using IntelliJ IDEA with the Go plugin, or GoLand and using Go 1.11 or newer, you can enable Go modules by going to Preferences -> Languages & Frameworks -> Go -> Go Modules (vgo) and check the box 'Enable Go Modules (vgo) integration'.
When you have a project which was properly initialised by go mod init, and therefore has a go.mod and go.sum file, it will download the dependencies when building from command line with go build or from IntelliJ by pressing the green play icon.
However, the import statements to remote dependencies might still be red, even though they seem to have been downloaded and appear in the go.mod file.
Curiously enough, the go project will actually run from the command line, just not from within IntelliJ. Why is this and how can I fix this?
go mod help 查看帮助
go mod init&amp;amp;amp;lt;项目模块名称&amp;amp;amp;gt;初始化模块，会在项目根目录下生成 go.mod文件。
go mod tidy根据go.mod文件来处理<em>依赖</em>关系。