首页 > 后端开发 > Golang > 正文

Go Buildpack 无法找到本地模块。我缺少什么?

WBOY
发布: 2024-02-13 11:21:07
转载
697人浏览过

go buildpack 无法找到本地模块。我缺少什么?

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: "测试"

我做了什么:

  1. 我已将模块名称更改为网址(即 test -> some.com/test),并在 go.mod 中使用替换指令来指向模块。
  2. 我运行了 go modvendor 并查看了生成的内容...some.com 就在那里!
  3. 我尝试过通过飞行发射进行本地和远程构建。两者都会导致没有这样的文件。

我现在正在尝试私人仓库。

解决方法

这不是一个很好的解决方案,但仍然可以编辑主机文件以使模块指向本地文件服务器。

# vim /etc/hosts
127.0.0.1    <module name>
登录后复制

如果我发现问题是出在 fly 还是 buildpack 上,我会编辑这个答案。问题是当 fly 运行 go modvendor 时,它不遵守 go.mod 中的替换指令。

只要模块名称采用 url 格式,自行运行的 go mod供应商就会正确复制所有内容。它不必是有效的网址。

另一个解决方案是简单地将代码托管在有效的 url 上并完成它。我可能缺少一面旗帜,但我还没有找到它。我希望遇到此问题的任何人都可能会发现此答案同时有所帮助。

以上就是Go Buildpack 无法找到本地模块。我缺少什么?的详细内容,更多请关注php中文网其它相关文章!

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
相关标签:
来源:stackoverflow网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号