Cgit and golang modules
Recently I started to self host my public git repositories on https://git.ewintr/nl. There are several options to choose from if you want that sort of thing, like Gitea or Gogs and others. These all look like fine applications, but they all try to imitate the big hosted platforms like Github and GitLab. They do more that making your repositories available to the web, they also include issue trackers, users, project management, etc. That's a bit too much for me. I only want to offer the code of my personal projects that I write about, nothing more.
Fortunately I found cgit. Cgit does just that. No collaboration features, but it does its job in a fast, simple and clean way. If its good enough for the Linux kernel, it's good enough for me. This blogpost covers how to set it up on Debian.
If you use this for hosting Go projects, there is however an extra step you should take. The location for remote Go modules are indicated by import strings at the top of your code and in your
go.mod file that indicate an url. But a string alone is not enough to make everything work smoothly in the background, if you for instance use
go get, or
go mod tidy. There are different types of version control systems, different protocols to transport the data, like
ssh. Did you know that git even has its own protocol for serving repositories? (See git-dameon for that. It's even lighter than cgit, but insecure, so
go get doesn't want to download over it without extra confirmation, which is a hassle.)
The extra ingredient necessary for making
go get work with a remote repository is an extra
<meta> tag in the header of the repository's website. See the documentation here for the details.
Luckily, someone already modified
cgit with an option to provide this tag:
extra-head-content. We can pass the necessary
<meta> tag unmodified through this setting. For instance, this is the configuration of one of the repositories on my instance:
repo.url=go-kit repo.owner=Erik Winter repo.path=/var/repo/public/go-kit/ repo.desc=a small, personal collection of useful go packages repo.extra-head-content=<meta name="go-import" content="git.ewintr.nl/go-kit git https://git.ewintr.nl/go-kit">