go mod init
因而就有一个 go.mod
和 go.sum
文件,它将在命令行中使用以下命令下载依赖项 go build
or from IntelliJ by pressing the green play icon. 或者按下绿色的play图标就可以得到IntelliJ。 但是,到远程依赖项的导入语句可能仍然是红色的,即使它们似乎已经下载并出现在go.mod
文件中奇怪的是,go项目实际上是从命令行运行的,而不是从IntelliJ内部运行的。为什么是这样的,我该怎么做?
The reason this approach does not work, has to do with the configuration in IntelliJ. That is why it will work from command line, just not in IntelliJ.
There are two ways to fix this:
With the first approach the dependencies defined in your go.mod
file might be re-downloaded, for example when the go project is run from a place where these dependencies are not in the local package registry.
With the second approach the dependencies are put in the 'vendor' folder and do not necessarily need to be re-downloaded, they are sort of made part of the project.