Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why we should use a URL for the Go module name?

What is the benefit of using URL for Go module name?

E.g:

sample.com/learn

Is it better than using just a simple name as a module name?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

There are two benefits to this particular naming style.

Globally unique names

The first benefit is the same as why Java uses a similar convention for package names: If (the beginning of) your package name is a registered domain name that is under your control, then you can guarantee that your package name will be unique, without the Go community having to run their own global distributed package registry database – the ICANN already does that for you.

Location, Location, Location

The go get command knows how to automatically download packages whose name looks like a partial URI, using only the name. Again, this means that the Go community does not have to run their own package repository (like e.g. the NPM registry, RubyGems.Org, PyPI, CPAN, CTAN, etc.) but they can just let "the web" be the package registry.

This allows the package name to not only be a unique identifier but also a locator, at the same time. In other words, instead of maintaining three different things, a name, an ID, and locator, you only need the name.

This is similar to how ECMAScript modules are also referred to by URIs in web scripts, or how Deno uses URIs in module names for TypeScript.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading