Skip to content

Installation

  • Go 1.26 or later
  • GOEXPERIMENT=jsonv2 enabled (this library uses encoding/json/v2)
  • An active Go module (go.mod)

Run this in your project directory:

Terminal window
GOEXPERIMENT=jsonv2 go get github.com/larsartmann/go-branded-id

This library imports encoding/json/v2, which requires the jsonv2 experiment flag. Set it for all Go commands:

Terminal window
export GOEXPERIMENT=jsonv2

For a permanent setup, add it to your shell profile (~/.bashrc, ~/.zshrc) or to go env:

Terminal window
go env -w GOEXPERIMENT=jsonv2
package main
import (
"fmt"
"github.com/larsartmann/go-branded-id"
)
type UserBrand struct{}
type UserID = id.ID[UserBrand, string]
func main() {
userID := id.NewID[UserBrand]("user-123")
fmt.Println(userID.Get()) // user-123
}
Terminal window
GOEXPERIMENT=jsonv2 go list -m github.com/larsartmann/go-branded-id