英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论