What should I name my Go package if I don't know where I will host it?

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

What should I name my Go package if I don't know where I will host it?

问题

如果你最终决定将其托管在其他位置而不是GitHub上,那么go mod init github.com/user/hello是否是一个正确的名称,我想写一个新的Go包。

英文:

I want to write a new Go package. If I type go mod init github.com/user/hello, would that be a correct name, if I end up deciding to host it in another location and not github?

答案1

得分: 1

你可以稍后重命名模块,因此它并不重要。继续使用它即可。

要在go.mod中重命名模块,你可以编辑它(它是一个简单的文本文件),或者可以运行以下命令:

go mod edit -module github.com/newuser/newhello

请注意,这只会在go.mod中重命名模块,但如果你的模块由相互导入的多个包组成,import语句不会被编辑,你需要手动编辑它们或使用工具来完成。

如果你想在将模块推送到远程仓库之前测试它,请参考https://stackoverflow.com/questions/52328952/how-to-use-a-module-that-is-outside-of-gopath-in-another-module/52330233#52330233

英文:

You can rename the module later, so it plays no important part. Keep using that.

To rename a module in go.mod, you may edit it (it's a simple text file), or you may run the command:

go mod edit -module github.com/newuser/newhello

Note that this will only rename the module in go.mod, but if your module consists of multiple packages which import each other, the import statements will not be edited, you have to manually edit those or use a tool to do that.

If you want to test your module before pushing it to a remote repository, see https://stackoverflow.com/questions/52328952/how-to-use-a-module-that-is-outside-of-gopath-in-another-module/52330233#52330233

huangapple
  • 本文由 发表于 2021年5月25日 16:12:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/67684127.html
匿名

发表评论

匿名网友

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

确定