Search code examples
gogithubmodulerepository

How to host a public golang module not on github


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).


Solution

  • 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.