go.mod necessary for GitHub package?

103 views
Skip to first unread message

Patrick

unread,
May 16, 2021, 2:25:23 AM5/16/21
to golang-nuts
Hello all,

I have a small package without any dependencies (besides standard library) on GitHub. Just a single .go file and a test file. 

Question: do I need a go.mod file? Does it give any advantages over not having one?

The package works fine by just importing it.

Patrick

(The package is located at https://github.com/speedata/hyphenation )

Manlio Perillo

unread,
May 16, 2021, 9:30:10 AM5/16/21
to golang-nuts
The advantage of adding a go.mod file is not for you, but for people that will add your package as a dependency.

Manlio


Patrick

unread,
May 16, 2021, 9:36:53 AM5/16/21
to golang-nuts
OK, but what are the advantages for others?

For my projects I use modules (locally) to have a list of dependencies with a checksum so builds could be reproducible. This works for remote packages with and without go.mod. What is the actual value for other users? Is this about versioning (semantic versioning)? Or is it easier to checksum?

Thanks 

Patrick


Manlio Perillo

unread,
May 16, 2021, 10:04:38 AM5/16/21
to golang-nuts
One example (not tested) is the case of a module X that depends on A and B.
A depends on an old version of github.com/speedata/hyphenation, and B depends on a new version (that is compatible with the old version but has a new API).

In GOPATH mode, X can not be built.


Manlio

Manlio Perillo

unread,
May 16, 2021, 10:07:35 AM5/16/21
to golang-nuts
Sorry, I used an incorrect example.  The final user is supposed to be in module mode and even if in GOPATH mode, the latest version is still compatible with the old version.
Reply all
Reply to author
Forward
0 new messages