Performing a v2 release of a Go module
On Wednesday, I'll be releasing oapi-codegen v2, which is my first v2 release of a Go module.
To prepare for this I've been practicing doing a v2 release, so thought I'd write about as a form of blogumentation.
The changes required aren't too large, we need to:
- Update the
go.mod
to note the new v2 module import path - Update any files that contain the module import path to include the
/v2
- (Perform any breaking changes required)
- Commit + tag as v2.0.0
Let's take the example of a very small Go module:
module gitlab.com/tanna.dev/jvt.me-examples/private-gitlab-subgroup-go/for-post
go 1.20
This then has two files, pkg/domain/person.go
:
package domain
type Person struct {
Name string
}
And pkg/greeting/main.go
:
package greeting
import (
"fmt"
"gitlab.com/tanna.dev/jvt.me-examples/private-gitlab-subgroup-go/for-post/pkg/domain"
)
func Greeting(p domain.Person) string {
return fmt.Sprintf("Hello %s", p.Name)
}
Following the steps above, we'll make the following changes.
To go.mod
:
-module gitlab.com/tanna.dev/jvt.me-examples/private-gitlab-subgroup-go/for-post
+module gitlab.com/tanna.dev/jvt.me-examples/private-gitlab-subgroup-go/for-post/v2
And then to pkg/greeting/main.go
:
import (
"fmt"
- "gitlab.com/tanna.dev/jvt.me-examples/private-gitlab-subgroup-go/for-post/pkg/domain"
+ "gitlab.com/tanna.dev/jvt.me-examples/private-gitlab-subgroup-go/for-post/v2/pkg/domain"
)
Not too bad, all things considered!
If you have a command-line tool associated with this, you'll need to make sure to update go install
docs accordingly:
-go install gitlab.com/tanna.dev/jvt.me-examples/private-gitlab-subgroup-go/for-post/cmd/greet@latest
+go install gitlab.com/tanna.dev/jvt.me-examples/private-gitlab-subgroup-go/for-post/v2/cmd/greet@latest