英文:
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/<github_user_name>/<module_name>@v0.1.0
In your case, it will be
GOPROXY=proxy.golang.org go list -m github.com/dylhunn/dragontoothmg@v0.1.0
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论