How to publish a Go package

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

How to publish a Go package

问题

我正在尝试发布我的Go包,以便在文档搜索Go搜索中可见,并且可以使用go get进行安装。

然而,我找到的一个文档没有明确告诉我如何生成和托管文档,或者如何发布包。我应该如何发布我的包?

英文:

I am trying to publish my Go package so it is visible on doc search and go search, and can be installed with go get.

However, the one document I found doesn't clearly tell me how to get the documentation generated and hosted, or to publish the package at all. How can I publish my package?

答案1

得分: 35

你已经做到了。

要“发布”一个Go包,你只需要通过公共URL使其可用。通过将其放在GitHub上,你已经发布了你的包。你可以查看GoDoc来证明。文档搜索可能需要一些时间来更新,但一旦你自己加载了GoDoc一次,索引就会自动进行。

至于Go搜索,只需点击页面顶部的Add Packages链接即可。

英文:

You already did it.

All you must do to "publish" a Go package is make it available via a public URL. By putting it on GitHub, you have already published your package. You can view the GoDoc as proof. It may take time for the doc search to update, but once you've loaded the GoDoc once on your own, the indexing will happen automatically.

As for Go search, just click the Add Packages link at the top of the page.

答案2

得分: 18

要将Go模块发布到公共URL,并使其在https://pkg.go.dev/上可见和可下载,您需要按照以下步骤进行操作:

首先,将您的包上传到一个公共URL,该URL必须包含您的包的许可证,在您的情况下是:

github.com/dylhunn/dragontoothmg

然后,为您的包源代码分配一个标签,并将其推送到GitHub。有关详细信息,请参阅https://golang.org/doc/modules/publishing

git tag v0.1.0
git push origin v0.1.0

在更新golang代理服务器的索引之前,您的包将无法立即被搜索到。使用以下命令显式告知代理服务器更新索引:

GOPROXY=proxy.golang.org go list -m github.com/<github_user_name>/<module_name>@v0.1.0

在您的情况下,命令将是:

GOPROXY=proxy.golang.org go list -m github.com/dylhunn/dragontoothmg@v0.1.0
英文:

For publishing go modules to public URL and make it visible and downloadable at https://pkg.go.dev/:

First, upload your package to a public URL which must have a license for your package in your case it is

github.com/dylhunn/dragontoothmg

After this assign a tag to your package source and push it to GitHub for details see https://golang.org/doc/modules/publishing

git tag v0.1.0
git push origin v0.1.0

Your package will not be searchable immediately until you explicitly tell the golang proxy server for updating their index using the below command

GOPROXY=proxy.golang.org go list -m github.com/&lt;github_user_name&gt;/&lt;module_name&gt;@v0.1.0

In your case, it will be

GOPROXY=proxy.golang.org go list -m github.com/dylhunn/dragontoothmg@v0.1.0

huangapple
  • 本文由 发表于 2017年5月1日 17:05:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/43716691.html
匿名

发表评论

匿名网友

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

确定