如何在 GitHub 以外的地方托管公共的 Golang 模块?

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

How to host a public golang module not on github

问题

我是一个绝对的Go语言新手,我确定这是一个新手问题。但是我找不到一个直接的答案,而且我怀疑不是我的问题。

模块路径的存储库部分如何映射到URL?所有在go.dev上的示例都使用github.com作为存储库,但是如果我想分享我编写的模块,它将不会在github上。是否有可能在其他地方公开托管?(我的非Go语言项目在sr.ht上,那将是我的首选)。

英文:

I'm an absolute newbie in golang, and I'm sure this is a newbie question. But having no luck finding a straight answer, and I suspect it is not me.

How exactly does the repository part of a module path map to an URL? All the examples on go.dev use github.com as the repository, but if I ever want to share a module I write, it won't be on github. Is it possible at all to publicly host elsewhere? (My non-golang projects are on sr.ht, and that would be my first choice).

答案1

得分: 0

你可以参考golang文档中的远程导入路径,但我怀疑,根据你提到的sr.ht,你可以直接写成:

import "git.sr.ht/~user/repo.git/path/to/module"

.git 告诉go它将查找一个git仓库。Go还会尝试首先使用https协议,所以不需要指定。

英文:

You can reference to golang docs at remote import paths, but I suspect, using your mention of sr.ht, you can just write

import "git.sr.ht/~user/repo.git/path/to/module"

The .git tells go that it will be looking at a git repository. Go will also try to use the https protocol first, so that does not need to specified.

huangapple
  • 本文由 发表于 2023年4月19日 00:40:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76047093.html
匿名

发表评论

匿名网友

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

确定