Should a Golang module name follow the name of its GitHub repository?

4 weeks ago 29
ARTICLE AD BOX

I am making a Go package. It is located, on GitHub, at https://github.com/eliotttak/go-ansi-colors. I would want that the Go module name would be github.com/eliotttak/ansicolors, because the go part of the name is useful only on GitHub, to clarify, but not in a Go project (it is obvious that I won't import an NPM package into a Go project, for example). I also want to remove the dashes because in a Go program, they can't be here.

Now, I have to manually rename the package, as it:

package main import ansicolors "github.com/eliotttak/go-ansi-colors"

I don't want to rename my GitHub repository!

In others term, I would want, in the go.mod of the repository https://github.com/eliotttak/go-ansi-colors, this line:

module github.com/eliotttak/ansicolors

And Go should automatically search here when typing go get github.com/eliotttak/ansicolors.

Is there a way to do it? Else, what is the recommended method?

Read Entire Article