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.3 Resolving Go version Candidate version sources (in priority order): go.mod -> ">= 1.19" -> "" Selected Go version (using go.mod): 1.19.5 Executing build process Installing Go 1.19.5 Completed in 35.526s Generating SBOM for /layers/paketo-buildpacks_go-dist/go Completed in 0s Paketo Buildpack for Go Mod Vendor 1.0.7 Checking module graph Running 'go mod graph' Completed in 1.166s Executing build process Running 'go mod vendor' Completed in 9.851s Generating SBOM for /workspace/go.mod Completed in 21ms Paketo Buildpack for Go Build 2.0.8 Executing build process Running 'go build -o /layers/paketo-buildpacks_go-build/targets/bin -buildmode pie -trimpath .' Failed after 611ms failed to execute 'go build': exit status 1 handlers.go:5:2: cannot find package "." in: /workspace/vendor/templates main.go:8:2: cannot find package "." in: /workspace/vendor/test ERROR: failed to build: exit status 1 Error failed to fetch an image or build from source: executing lifecycle: failed with status code: 51
handlers.go:5:2: “模板”
main.go:8:2: "测试"
我现在正在尝试私人仓库。
这不是一个很好的解决方案,但仍然可以编辑主机文件以使模块指向本地文件服务器。
# vim /etc/hosts 127.0.0.1 <module name>
如果我发现问题是出在 fly 还是 buildpack 上,我会编辑这个答案。问题是当 fly 运行 go modvendor 时,它不遵守 go.mod 中的替换指令。
只要模块名称采用 url 格式,自行运行的 go mod供应商就会正确复制所有内容。它不必是有效的网址。
另一个解决方案是简单地将代码托管在有效的 url 上并完成它。我可能缺少一面旗帜,但我还没有找到它。我希望遇到此问题的任何人都可能会发现此答案同时有所帮助。
以上是Go Buildpack 无法找到本地模块。我缺少什么?的详细内容。更多信息请关注PHP中文网其他相关文章!