Performing a v2 release of a Go module

Featured image for sharing metadata for article

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

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

#blogumentation #go.

This post was filed under articles.

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.