-1

我正在将我的Golang程序从 Windows 迁移到 Centos 7

它在 Windows 中运行良好,
但是当我尝试在 centos 上编译时,我得到了类似的错误

main.go:20:3: cannot find package "github.com/BurntSushi/toml" in any of:
        /usr/local/go/src/github.com/BurntSushi/toml (from $GOROOT)
        /root/work/src/github.com/BurntSushi/toml (from $GOPATH)
main.go:15:3: cannot find package "github.com/dgrijalva/jwt-go" in any of:
        /usr/local/go/src/github.com/dgrijalva/jwt-go (from $GOROOT)
        /root/work/src/github.com/dgrijalva/jwt-go (from $GOPATH)
main.go:16:3: cannot find package "github.com/gwlkm_service/config" in any of:
        /usr/local/go/src/github.com/gwlkm_service/config (from $GOROOT)
        /root/work/src/github.com/gwlkm_service/config (from $GOPATH)

对centos有点新,所以不知道该怎么做

4

2 回答 2

1

看起来你已经配置了你的 GOPATH,没有 Go Module,你可以go get [package path]用来下载导入的包。

go get github.com/BurntSushi/toml
go get github.com/dgrijalva/jwt-go
go get github.com/gwlkm_service/config
于 2019-12-30T06:58:56.457 回答
0

恰恰

您在服务器上的 go 安装似乎在/usr/local/go并且您的项目在其中,/root/work 因此您的所有依赖项都应该在/root/work/src/usr/local/go/src

现在开始行动检查你GOPATH的运行echo $GOPATH 假设它自动设置为/usr/local/go/src 如果没有然后遵循 -如何在 Ubuntu 上设置 GOPATH 环境变量?我必须编辑什么文件?

如果一切正常,则在您的文件夹中运行go mod init

这将创建 mod 文件,这将帮助您进一步安装查看 - https://blog.golang.org/using-go-modules

然后运行上面的 go get 命令@beiping96 说

go get github.com/BurntSushi/toml go get github.com/dgrijalva/jwt-go go get github.com/gwlkm_service/config

注意 - 完成上述过程后,您将生成 go modules 文件(与 package.json 相同),将来您将不需要关心依赖项

于 2019-12-30T07:40:19.207 回答