使用go.mod部署到Google App Engine flexible失败,因为它正在GOPATH中寻找依赖库 [英] Deploying to google app engine flexible with go.mod fails because it is looking for dependent libraries in GOPATH

查看:62
本文介绍了使用go.mod部署到Google App Engine flexible失败,因为它正在GOPATH中寻找依赖库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个来自此处的helloworld应用修改.

I have the helloworld app from here with a couple of modifications.

  1. 我使用过logrus(将依赖关系引入到外部库中)
  2. 我已经使用go mod init添加了go.mod
  3. 我已经在我的GOPATH外部签出了这段代码.

一切都可以在localhost上进行.我可以在localhost:8080上看到问候消息.当我尝试进行gcloud应用程序部署时,出现以下错误:

Everything works on localhost. I'm able to see the hello message on localhost:8080. When I attempt to do a gcloud app deploy I get the following error:

staging for go1.11
Staging Flex app: failed analyzing /home/.../code/app-engine-gomod: cannot find package "github.com/sirupsen/logrus" in any of:
    ($GOROOT not set)
    /home/.../go/src/github.com/sirupsen/logrus (from $GOPATH)
GOPATH: /home/.../go

无论是否有 go mod vendor ,我尝试过都无济于事.我在做什么错了?

I've tried with and without go mod vendor doesn't help. What am I doing wrong?

推荐答案

我为您提供了一种解决方法-这并不漂亮.我不知道为什么App Engine不尝试使用go模块来解决依赖关系,而是只在$ GOPATH中查找.

I have a workaround for you - it's not pretty. I don't know why app engine doesn't try to resolve dependencies with go modules and instead looks just in the $GOPATH.

我的解决方法是将go模块缓存中的相应文件夹复制回Go Path.我很想知道是否有人有更好的解决方案.

My workaround is to just copy the appropriate folder in go modules cache back to the Go Path. I'd love to know if someone has a better solution.

您的mod缓存应位于 $ GOPATH/pkg/mod

Your mod cache should be in $GOPATH/pkg/mod

将所需的依赖项复制到 $ GOPATH/src 文件夹中,您应该会很好.

Copy the dependencies you need, into your $GOPATH/src folder and you should be good to go.

相关问题,希望对您有所帮助.这使我陷入困境,因为我最近切换到了Go模块,而GAE则抱怨依赖项的错误,该依赖项已在较新版本中修复.我多次更新了依赖关系,它在本地测试中运行良好,但是在 app deploy 上仍然遇到相同的错误.最终,我意识到发生了什么:在本地运行代码时,Go从go模块缓存中正确组装了依赖关系-应用引擎从Go Path的旧"位置获取了依赖.启用Go模块后, go get 仅更新mod缓存.

Related issue, hope this helps someone. This led me down a rabbit hole because I recently switched to Go modules, and GAE was complaining about a bug in a dependency which was fixed in a newer version of it. I updated the dependency multiple times, it worked fine on local testing but I kept getting the same error on app deploy. Eventually I realised what was happening: when running your code locally, Go correctly assembled dependencies from the go modules cache - app engine was taking it from the 'old' location from the Go Path. Once you enable Go modules go get only updates the mod cache.

这篇关于使用go.mod部署到Google App Engine flexible失败,因为它正在GOPATH中寻找依赖库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆