【踩坑记录】创建Go模块-从其他远程模块调用代码教程时遇到发布Go模块到远程中央仓库失败

问题解构三步走

实践Go官方教程时,遇到发布Go模块到远程中央仓库失败。

1.认识问题

参考 Publishing a module-发布模块 文档尝试发布Go模块到远程中央仓库。

现场日志

PS D:\workspaces\Go\golang-learn\tutorial\create-module\greetings> go list -m golang-learn/tutorial/create-module/[email protected]
go: golang-learn/tutorial/create-module/[email protected]: malformed module path "golang-learn/tutorial/create-module/greetings": missing dot in first path element

PS D:\workspaces\Go\golang-learn\tutorial\create-module\greetings> go list -m github.com/bert82503/golang-learn/tutorial/create-module/[email protected]
go: github.com/bert82503/golang-learn/tutorial/create-module/[email protected]: invalid version: unknown revision tutorial/create-module/greetings/v0.1.0

2.分析问题

通过日志找线索

go: golang-learn/tutorial/create-module/[email protected]: malformed module path "golang-learn/tutorial/create-module/greetings": missing dot in first path element

模块路径“golang-learn/tutorial/create-module/greetings”格式错误:第一个路径元素中缺少点号

go: github.com/bert82503/golang-learn/tutorial/create-module/[email protected]: invalid version: unknown revision tutorial/create-module/greetings/v0.1.0

无效版本:未知版本“tutorial/create-module/greetings/v0.1.0”

Tutorial: Get started with Go-"你好,世界"新手入门教程 中,"rsc.io/quote"是一个有效的模块名称。

再结合 Naming a module-命名模块 文档,问题原因可能是无效的模块名称引起。

3.解决问题

使用正确的模块名称后,发布模块到远程中央仓库成功。

go list -m github.com/bert82503/[email protected]

这个Go模块的远程中央仓库地址:
https://pkg.go.dev/github.com/bert82503/golang-learn

参考 Deprecation of ‘go get’ for installing executables 文档发现,可以使用 go install 发布模块。

go install github.com/bert82503/[email protected]

猜你喜欢

转载自blog.csdn.net/shupili141005/article/details/127827194
今日推荐