go mod init 在初始化时出现 cannot determine module path for source directory (outside GOPATH

问题:

新创建的golang项目,使用 go mod init 命令时出现 cannot determine module path for source directory xxxxxxx (outside GOPATH, module path must be specified)

解决方案:

这是因为go mod init 初始化项目时,需要定义一个 module ,我们打开一个 go.mod 文件,就会发现第一行就有

module ProjectName

因此,在执行 go mod init 时需要定义 module,如:

go mod init ProjectName

猜你喜欢

转载自blog.csdn.net/qq980338445/article/details/107847578