Go模块导入 – 无效的版本:go.mod文件具有格式错误的模块路径。

huangapple go评论75阅读模式
英文:

Go Module Import - Invalid version: go.mod has malformed module path

问题

我已经在各个地方寻找了关于"go.mod具有格式错误的模块路径"的答案,但我没有找到为什么我无法导入我正在编写的库的答案。为了简化问题,我创建了一个小型的库存储库:https://github.com/buphmin/test-go-pkg

注意:我正在使用stripe api库作为结构灵感。https://github.com/stripe/stripe-go

问题:

我创建了一个库,使用"go mod init "命令,将代码推送到github并打上标签。然后尝试导入该包以在其他地方使用该库,但是我收到了一个错误消息:"go get: github.com/buphmin/test-go-pkg@v1.0.0: invalid version: go.mod has malformed module path "github.com/buphmin/test-go-pkg/v1" at revision v1.0.0"

我不知道为什么会出现这个问题,到目前为止我还没有找到答案。

重现步骤:

假设您已经安装了Go。

  • 创建本地文件夹
  • 运行"go mod init <your_mod>"命令
  • 运行"go get github.com/buphmin/test-go-pkg/v1"命令
  • 出现错误

其他信息:

  • Go版本:v1.16
  • Ubuntu 18 LTS

go mod文件:

从上面列出的源代码中复制:

module github.com/buphmin/test-go-pkg/v1

go 1.16

编辑 - 答案:

在@Steven Penny的帮助下,我现在理解了v1、v2等的意义不仅仅是组织。这篇文章解释了Go如何处理版本控制:https://www.honeybadger.io/blog/golang-go-package-management。

英文:

I have looked all over for an answer for "go.mod has malformed module path" but I have not found an answer to why I can't get a library I am writing to import. To simplify I have made a tiny library repo: https://github.com/buphmin/test-go-pkg

Note: I am using the stripe api library for structure inspiration. https://github.com/stripe/stripe-go

Problem:

I create a library, go mod init <pkg>, push code and tag to github. Then try to import package to use the library elsewhere and I get an error message: 'go get: github.com/buphmin/test-go-pkg@v1.0.0: invalid version: go.mod has malformed module path "github.com/buphmin/test-go-pkg/v1" at revision v1.0.0'

I have no idea why this is an issue and I have not found an answer thus far.

Steps to Reproduce

Assuming you have go installed.

  • Create local folder
  • go mod init <your_mod>
  • go get github.com/buphmin/test-go-pkg/v1
  • error occurs

Other info

  • go v1.16
  • ubuntu 18 LTS

go mod file
Copied from the source of truth listed above: https://github.com/buphmin/test-go-pkg

module github.com/buphmin/test-go-pkg/v1

go 1.16

Edit - Answer:

My understand now with the help of @Steven Penny is that v1, v2, etc has more significance than just organization. This article explains how go treats that versioning https://www.honeybadger.io/blog/golang-go-package-management.

答案1

得分: 3

这个:

module github.com/buphmin/test-go-pkg/v1

是无效的。应该是这样的:

module github.com/buphmin/test-go-pkg
英文:

This:

module github.com/buphmin/test-go-pkg/v1

is not valid. Should be this:

module github.com/buphmin/test-go-pkg

huangapple
  • 本文由 发表于 2021年5月31日 05:23:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/67765942.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定