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

1 问题

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

2 解决方案

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

module ProjectName

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

go mod init ProjectName

猜你喜欢

转载自blog.csdn.net/ygq13572549874/article/details/130819899