php小编香蕉在使用Go Buildpack时遇到了一个问题:“无法找到本地模块,我缺少什么?”。Go Buildpack 是用于在Cloud Foundry平台上构建和运行Go应用程序的工具。这个问题通常是由于缺少Go依赖库或者配置不正确导致的。解决这个问题的方法是检查Go项目的依赖关系,并确保正确设置了GOPATH和GO111MODULE等环境变量。
问题内容
我正在尝试在 https://fly.io 上构建并启动 go 应用程序,但在构建时无法找到我的测试和模板包,如下所示:
. ├── cmd │ ├── doc │ │ ├── go.mod │ │ └── main.go │ ├── git │ │ ├── go.mod │ │ └── main.go │ ├── imp │ │ ├── go.mod │ │ └── main.go │ ├── log │ │ ├── go.mod │ │ └── main.go │ ├── met │ │ ├── go.mod │ │ └── main.go │ ├── orc │ │ ├── go.mod │ │ └── main.go │ ├── pub │ │ ├── go.mod │ │ └── main.go │ ├── rep │ │ ├── go.mod │ │ └── main.go │ └── web │ ├── fly.toml │ ├── go.gen │ ├── go.mod │ ├── go.sum │ ├── handlers.go │ ├── handlers_test.go │ ├── main.go │ ├── main_test.go │ ├── router.go │ └── router_test.go ├── contributing.md ├── go.mod ├── go.work ├── internal ├── license.txt ├── main.go ├── pctl ├── pkg │ ├── **templates** │ │ ├── base.qtpl │ │ ├── base.qtpl.go │ │ ├── go.mod │ │ ├── go.sum │ │ ├── whoami.qtpl │ │ └── whoami.qtpl.go │ └── **test** │ ├── go.mod │ └── test.go └── readme.md
登录后复制
https://paketo.io/docs/reference/go-reference/#package-management-with-go-modules 状态:
the buildpack will vendor dependencies using go modules if the app source code contains a go.mod file. during the build phase, the go-mod-vendor buildpack(opens in a new tab) checks to see if the application requires any external modules and if it does, runs the go mod vendor command for your app. the resulting vendor directory will exist in the app’s root directory and will contain all packages required for the build.
登录后复制
查看构建日志,我发现 go modvendor 确实已运行。
Paketo Buildpack for Go Distribution 2.2.3Resolving Go versionCandidate version sources (in priority order):go.mod -> ">= 1.19" -> ""Selected Go version (using go.mod): 1.19.5Executing build processInstalling Go 1.19.5Completed in 35.526sGenerating SBOM for /layers/paketo-buildpacks_go-dist/goCompleted in 0sPaketo Buildpack for Go Mod Vendor 1.0.7Checking module graphRunning 'go mod graph'Completed in 1.166sExecuting build processRunning 'go mod vendor'Completed in 9.851sGenerating SBOM for /workspace/go.modCompleted in 21msPaketo Buildpack for Go Build 2.0.8Executing build processRunning 'go build -o /layers/paketo-buildpacks_go-build/targets/bin -buildmode pie -trimpath .'Failed after 611msfailed to execute 'go build': exit status 1handlers.go:5:2: cannot find package "." in:/workspace/vendor/templatesmain.go:8:2: cannot find package "." in:/workspace/vendor/testERROR: failed to build: exit status 1Error failed to fetch an image or build from source: executing lifecycle: failed with status code: 51
登录后复制
handlers.go:5:2: “模板”main.go:8:2: “测试”
我做了什么:
我已将模块名称更改为网址(即 test -> some.com/test),并在 go.mod 中使用替换指令来指向模块。我运行了 go modvendor 并查看了生成的内容…some.com 就在那里!我尝试过通过飞行发射进行本地和远程构建。两者都会导致没有这样的文件。
我现在正在尝试私人仓库。
解决方法
这不是一个很好的解决方案,但仍然可以编辑主机文件以使模块指向本地文件服务器。
# vim /etc/hosts127.0.0.1
登录后复制
如果我发现问题是出在 fly 还是 buildpack 上,我会编辑这个答案。问题是当 fly 运行 go modvendor 时,它不遵守 go.mod 中的替换指令。
只要模块名称采用 url 格式,自行运行的 go mod供应商就会正确复制所有内容。它不必是有效的网址。
另一个解决方案是简单地将代码托管在有效的 url 上并完成它。我可能缺少一面旗帜,但我还没有找到它。我希望遇到此问题的任何人都可能会发现此答案同时有所帮助。
以上就是Go Buildpack 无法找到本地模块。我缺少什么?的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2483606.html