Golang导入包缺少依赖包。

huangapple go评论89阅读模式
英文:

golang import package missing dependency package

问题

我正在尝试在https://github.com/liyiheng/qnmahjong中设置项目,但是当我执行go build -o qnmahjong -ldflags "-X main.branch=git rev-parse --abbrev-ref HEAD -X main.commit=git rev-parse HEAD"时,它给我报了一个关于github.com/spf13/viper包的错误。我发现这个包的依赖需要github.com/hashicorp/hcl/hcl/printer,但是这个包已经不存在了。我该如何解决这个问题?而且这个项目没有go.mod文件。如果我设置GO111MODULE=on,又会出现没有go.mod文件的另一个问题。

英文:

I am trying to set up the project in https://github.com/liyiheng/qnmahjong, however, when I execute go build -o qnmahjong -ldflags "-X main.branch=git rev-parse --abbrev-ref HEAD -X main.commit=git rev-parse HEAD"

It gives me an error on package github.com/spf13/viper. I found that this package's dependency requires github.com/hashicorp/hcl/hcl/printer but that package is no longer exist. How can I fix this problem? And this project does not have go.mod file. If I set GO111MODULE=on, there will be another problem of having no go.mod file.

I am trying to setup the project in https://github.com/liyiheng/qnmahjong
However, when I execute go build -o qnmahjong -ldflags "-X main.branch=git rev-parse --abbrev-ref HEAD -X main.commit=git rev-parse HEAD"

It gives me an error on package github.com\spf13\viper . I found that this package's dependency requires github.com/hashicorp/hcl/hcl/printer but that package is no longer exist. How can I fix this problem? And this project does not have go.mod file. If I set GO111MODULE=on, there will be another problem of having no go.mod file.

答案1

得分: 1

你可以尝试在main.go所在的目录中运行以下命令:

go mod init github.com/liyiheng/qnmahjong

这将创建go.mod文件并尝试下载依赖项。从那里开始修复错误。

英文:

You could try running

go mod init github.com/liyiheng/qnmahjong

in the directory where the main.go lies. This will create the go.mod file and try to download the dependencies. Fix errors conitnuing from there.

huangapple
  • 本文由 发表于 2023年7月6日 22:05:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76629685.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定