在我的go build中遇到了依赖错误。

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

Getting a dependency error on my go build

问题

我在进行go build时遇到了依赖错误,但我还不理解它。在本地构建和编译时一切正常。问题出现在我尝试在Docker容器中运行和构建时。

错误信息如下:

go: github.com/go-openapi/errors@v0.20.3 需要
        gopkg.in/check.v1@v1.0.0-20200227125254-8fa46927fb4f: 无法识别的导入路径 "gopkg.in/check.v1": 读取 https://gopkg.in/check.v1?go-get=1 时出错: 502 Bad Gateway
        服务器响应: 无法从GitHub获取引用: 无法与GitHub通信: 获取 https://github.com/go-check/check.git/info/refs?service=git-upload-pack 时出错: net/http: 请求已取消 (Client.Timeout 超时)

看起来它无法访问该包以获取正确的版本(502错误),但也可能是我的go包中存在某种版本不匹配的问题。不确定如何解决。

这是我的构建命令:

RUN cd /go/src/webservice_redfalcon/ && go mod init && go mod tidy && go mod download
RUN cd /go/src/webservice_redfalcon/cmd/redfalcon-server && CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o /app/server

我的go版本是1.19。

非常感谢任何帮助。

英文:

I am getting a dependency error on my go build and I don't understand it yet. Building and compiling locally works just fine. The issue is when I try to run and build in my docker container then I get this error.

go: github.com/go-openapi/errors@v0.20.3 requires
        gopkg.in/check.v1@v1.0.0-20200227125254-8fa46927fb4f: unrecognized import path "gopkg.in/check.v1": reading https://gopkg.in/check.v1?go-get=1: 502 Bad Gateway
        server response: Cannot obtain refs from GitHub: cannot talk to GitHub: Get https://github.com/go-check/check.git/info/refs?service=git-upload-pack: net/http: request canceled (Client.Timeout exceeded while awaiting headers)

It appears that it cannot reach out to the package to get the correct version (502) but also could be some sort of version mismatch in my go packages. Not sure how to resolve.

Here is my build command:

RUN cd /go/src/webservice_redfalcon/ && go mod init && go mod tidy && go mod download
RUN cd /go/src/webservice_redfalcon/cmd/redfalcon-server && CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o /app/server

And my go version is 1.19

Any help would be much appreciated.

答案1

得分: 0

所以根本问题似乎是与github.com的连接以及获取软件包有关。一旦网络问题解决,502错误就消失了,一切正常运行。

英文:

So the root issue appeared to be some sort of connectivity with github.com and retrieving the package. Once that networking issue was fixed then the 502 went away and it worked fine.

huangapple
  • 本文由 发表于 2022年8月16日 02:16:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/73364916.html
匿名

发表评论

匿名网友

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

确定