发布一个golang模块:语义化版本控制

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

Publishing a golang module: Semantic versioning

问题

我一直在尝试为我的Web应用程序创建和发布一个Go语言SDK:https://datelist.io
在我的本地设置中一切都运行良好。然而,一旦我想要将SDK发布到https://pkg.go.dev/网站上,事情就变得更加困难了。

我想要发布的代码可以在这里找到:github.com/datelist/datelist-sdk-golang

我已经阅读了一些教程,如果我理解正确的话,我所需要做的就是:

  • 创建我的公共存储库
  • 在存储库的根目录下添加一个go.mod文件
  • 请求proxy.golang.org网站索引我的更改

我尝试了不同的方法来索引我的更改,根据这个链接:
https://go.dev/about/
其中一种解决方案是访问这个页面:
https://proxy.golang.org/MYMODULE_PATH

因此,我尝试了:
https://proxy.golang.org/github.com/datelist/datelist-sdk-golang/@v/v1.0.0.info

然而,我得到了以下错误:
not found: github.com/datelist/datelist-sdk-golang@v1.0.0: invalid version: unknown revision v1.0.0

我尝试了不同的方法。我在我的GitHub存储库上发布了两个标签:v1.0.0和1.0.0,但它不起作用。我检查了一下:我的代码看起来是有效的,并且版本似乎存在,因为我可以访问:https://proxy.golang.org/github.com/datelist/datelist-sdk-golang/@v/ce18fa0756c2.info
然而,当涉及到将我的SDK添加到go.dev时,我陷入了困境。

提前感谢您的帮助。

英文:

I've been trying to create and publish a golang SDK for my web application: https://datelist.io
Everything works well on my local setup. However, things are started to get more difficult once I'd like to publish my SDK to the https://pkg.go.dev/ website

The code I'd like to publish is available there: github.com/datelist/datelist-sdk-golang

I've read a few tutorials, and, if I understand correctly, all I needed was to:

  • Create my public repository
  • Add a go.mod file at the root of my repository
  • Ask the proxy.golang.org website to index my changes

I've tried different ways to index my changes, and, according to that link:
https://go.dev/about/
Once solution is to visit that page:
https://proxy.golang.org/MYMODULE_PATH

I've thus tried:
https://proxy.golang.org/github.com/datelist/datelist-sdk-golang/@v/v1.0.0.info

However, I've got the following error:
not found: github.com/datelist/datelist-sdk-golang@v1.0.0: invalid version: unknown revision v1.0.0

I've tried different things. I've published two tags on my github repository: v1.0.0 and 1.0.0 and it doesn't work. I've checked: my code looks valid, and the version seems to exist, as I can go to: https://proxy.golang.org/github.com/datelist/datelist-sdk-golang/@v/ce18fa0756c2.info
However, I'm stuck when it comes to adding my SDK to go.dev

Thanks in advance

答案1

得分: 2

你的 go.mod 文件(最新提交为 ce18fa)的模块名称是不正确的(不需要 /v1.0.0):

module github.com/datelist/datelist-sdk-golang/v1.0.0

在 git 发布标签 v1.0.0 上的 go.mod 指向了一个不存在的导入路径 datelist.io/sdk

module datelist.io/sdk

请将你的 go.mod 更新为以下内容(有效的 URL - 不带标签后缀):

module github.com/datelist/datelist-sdk-golang
    
go 1.16

然后将此提交的版本标记为 v1.0.1 - 这样你的模块就可以正常工作了。

你的库的使用者可以执行以下操作:

go get github.com/datelist/datelist-sdk-golang

或者显式地执行:

go get github.com/datelist/datelist-sdk-golang@v1.0.1

前者通过 git 标签隐式选择最新的 semver 版本 - 在这种情况下是 v1.0.1

英文:

Your go.mod (latest commit ce18fa) module name is incorrect (/v1.0.0 is not needed):

module github.com/datelist/datelist-sdk-golang/v1.0.0

the go.mod at git release tag v1.0.0 points to an import path datelist.io/sdk that does not exist:

module datelist.io/sdk

Update your go.mod to this (valid URL - with no tag suffix):

module github.com/datelist/datelist-sdk-golang
    
go 1.16

and then git tag this committed release as say v1.0.1 - and that should make your module work.

Consumers of your library can then:

go get github.com/datelist/datelist-sdk-golang

or explicitly:

go get github.com/datelist/datelist-sdk-golang@v1.0.1

The former implicitly chooses the latest semver version via git tags - v1.0.1 in this case.

huangapple
  • 本文由 发表于 2021年8月8日 13:05:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/68697945.html
匿名

发表评论

匿名网友

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

确定