vscode运行程序时报go: cannot find main module, but found Gopkg.lock

从git上clone代码到本地运行时,报如下错误

go: cannot find main module, but found Gopkg.lock in d:\go\src\appserver
	to create a module there, run:
	cd ..\.. && go mod init
exit status 1
Process exiting with code: 1

按照提示执行go mod init后又遇到

PS D:\go\src\appserver\cmd\appserver> go run appserver.go
go: github.com/Sirupsen/logrus: github.com/Sirupsen/[email protected]: parsing go.mod:
        module declares its path as: github.com/sirupsen/logrus
                but was required as: github.com/Sirupsen/logrus

之后便在go.mod中添加

replace github.com/sirupsen/logrus => /d/go/src/appserver/vendor/github.com/Sirupsen

但还是遇到一堆包报错,换了个思路,直接关闭GO111MODULE,git bash中执行

go env -w GO111MODULE=off

再查看go环境 变量,go env发现已经关闭GO111MODULE。

之后再运行代码,竟然成功了,看来确因GO111MODULE问题导致。

你可能感兴趣的:(云开发)