Easily host Go modules on your domain
29 Dec 2023
Go modules are an easy way to add dependencies to your project. Basically
it's a straight forward way to incorporate 3rd party modules (or packages) into
your own application. Most programming languages are only as strong as their
standard library and 3rd party community and in this area, Go is very very
strong. Sure Go modules have their issues but it's
mostly related to custom domain expiration or source forge account hijacking.
According to Go's crypto maintainer Filippo Valsorda the use of domains in the
module package is:
the strongest security guarantee you can offer without forcing each module
author to manage keys.
(Source)
One of the pain points of Go modules and using URLs as the module import path
is when the module has to move it's path for whatever reason. Common examples
are moving from one forge to another (ie, leaving GitHub for SourceHut,
which I highly recommend!) or maybe moving the project to a new version control
software all together (ie, migrating from Mercurial to Git).
Well this last example is what happened to me this week. I wanted to move some
Go projects from Mercurial to Git and that was a huge pain in the ass. Because
these projects really aren't used by anyone but my team and it really only
affected our projects, the outside effect on the community was not really felt.
However, it still was a chore to get the migration done.
Since I started with Go I wanted to write a simple server to manage Go modules
on my own domains for me. This way, I just import the one module path and if
the forge or vcs changes, it's literally just an update in the servers
database and everything continues in theory. Though I suppose an update on each
end users side is in order when switching from one vcs to another to account
for changeset hashes.
Anyway, I found a couple of projects aimed to tackle this but none scratched my
itch. They either stored all data in config files or didn't offer everything I
wanted. My idea is for a very simple, low requirement, solution to host my
modules and provide basic information to curious users who enter the module
URL in their web browser. Basically I wanted the following:
- Easy to deploy and run on any server
- Use sqlite3 for it's database
- Simple web interface to add/edit/remove modules. No file changes or app
restarts.
- Offer descriptive name (not just repo name) and full description of the
module.
- Have optional links for:
- Homepage URL
- Issues URL
- Mailing List URL
GoHome
So I wrote an application called GoHome to scratch my itch. It's a
simple server that will do all of the above mentioned.
You can [see an example here][carrier] for my module named carrier
. When
appending ?go-get=1
to the URL then you get a special header used by the Go
languages tooling to fetch the actual code from the specified repository.
It's free to use, alter, whatever and it's released under the BSD License. You
can view the project homepage to get some simple docs, the code,
issue tracker, etc.
I'd love to see some people using this in the wild and provide some feedback.
It's very simple and so far in my testing is working as expected. There are a
few small things I'd like to clean up and maybe add to it but not too much. So
if you've got any ideas for changes or improvements, please don't be shy.
[carrier]: https://petersanchez.com/x/carrier "Carrier"