Managing a public Go module
A simple guide on how to publish a Go module and manage it over time.
Preparation
... initialize git and connect to GitHub.
And feel free to write some code.
For best practice, don't forget to also add a LICENSE file.
Beta stage
Documentation: https://pkg.go.dev/github.com/yourname/module@v0.1.0
Installation: go get github.com/yourname/module@v0.1.0
Import: github.com/yourname/module
Always follow Semantic Versioning.
Release
Release it when you're sure that your code is stable for the wild.
Documentation: https://pkg.go.dev/github.com/yourname/module
Installation: go get github.com/yourname/module@v1.0.0
Import: github.com/yourname/module
New major releases
Create them for all breaking changes.
The previous major version should stay in a separate branch to allow releasing patches. So before making new changes, save the current code in a new branch:
Now you are ready for a major change:
Update module path in go.mod:
module github.com/yourname/module/v2
Update internal imports (if any):
// Change from:
import "github.com/yourname/module/subpackage"
// To:
import "github.com/yourname/module/v2/subpackage"
... make your changes.
Documentation: https://pkg.go.dev/github.com/yourname/module/v2
Installation: go get github.com/yourname/module/v2@v2.0.0
Import: github.com/yourname/module/v2
Example
You can see an example of a simple module that has gone through this life cycle here: https://github.com/cheatsnake/module
Corresponding links to go pkg: