Skip to content

chore: bring the module to Go 1.27 - #4

Merged
veggiemonk merged 5 commits into
mainfrom
chore/go-modernize
Sep 21, 2026
Merged

veggiemonk merged 5 commits into
mainfrom
chore/go-modernize

Conversation

@veggiemonk

Copy link
Copy Markdown
Owner

Brings the module and the four example modules to Go 1.27.

What the machines did

go get go@1.27.0, then modernize -fix ./... and go fix ./... in
each of the five modules. Each directory under examples/ is its own
module, so the root pass does not reach them.

  • an int32 counter becomes an atomic.Int32
  • a search loop becomes slices.Contains
  • three index loops become a range over an int
  • reflect.TypeOf(int(0)) becomes reflect.TypeFor[int]()

The CI workflows read go-version-file: go.mod, so they follow the new
version with no change.

encoding/json/v2

examples/advanced held the one JSON site. json.NewEncoder(file) with
SetIndent becomes json.MarshalWrite with jsontext.WithIndent. The
one encoding/json import that stays is the v1 options package, aliased
jsonv1.

Three v2 defaults needed an option:

default option why
a time.Duration gives an error jsonv1.FormatDurationAsNano(true) keeps the v1 nanosecond number. A struct tag would not reach the durations that Metadata holds in an any.
a struct with no exported field gives an error json.MarshalToFunc for error every value in Errors failed. The marshaler writes the message.
map members go out in read order json.Deterministic(true) the report is a file that a person reads and a diff compares.

MarshalWrite writes no trailing newline, which Encoder.Encode did, so
the export writes one.

Output change. The old binary and the new one were run and the bytes
compared. One difference stays, and it is the point of the error
marshaler:

-  "Errors": [{}]
+  "Errors": ["validation warnings: 37/38 records passed"]

A latent difference no run showed: a nil slice now writes [] and a nil
map {}, where v1 wrote null.

By hand

  • uuid. Go 1.27 makes UUIDs in the standard library, so
    UUIDMiddleware no longer needs github.com/google/uuid. Both give a
    version 4 UUID and the same lowercase hex-and-dash string, so the value
    in the context does not change. go mod tidy drops the dependency from
    all five modules.
  • Name. reflect.TypeFor[T]() replaces the zero-length array trick
    that read the package path of T through reflect.TypeOf(z).Elem().
    Same type, same zero allocations.
  • SafeCopy. new(*original), the Go 1.26 form of new, replaces
    the pair of a new(T) and an assignment.

Checked and left alone: no helper is superseded by slices, maps,
cmp, min or max, and the module does not use sort; no generic
helper exists whose only job is to change an element type; no struct is
embedded; and generalized type inference does not reach a conversion to
a generic type, so each StepFunc[T](...) in the tests keeps its type
argument.

Verification

In all five modules gofmt -l ., modernize -fix -diff ./... and
go fix -diff ./... print nothing, and build and vet are clean.
go test -race -count=1 -shuffle=on ./... passes, the benchmarks run,
and make examples runs all four examples end to end.

🤖 Generated with Claude Code

veggiemonk and others added 5 commits September 21, 2026 14:49
go get go@1.27.0, then modernize -fix ./... and go fix ./....

- middleware_test.go: the int32 counter becomes atomic.Int32
- workflow_error_test.go: a search loop becomes slices.Contains; an
  index loop becomes range over an int
- workflow_test.go: reflect.TypeOf(int(0)) becomes reflect.TypeFor[int]()

go fix -diff reports nothing. The CI workflows read go-version-file:
go.mod, so they follow the new version with no change.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Each directory under examples/ is its own module, so the root pass did
not reach them. Same steps: go get go@1.27.0, modernize -fix ./... and
go fix ./....

- examples/middleware: two index loops become range over an int

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
json.NewEncoder(file) with SetIndent becomes json.MarshalWrite with
jsontext.WithIndent. The one encoding/json import that stays is the v1
options package, aliased jsonv1.

Three v2 defaults needed an option, and the comment on exportOptions
gives the reason for each:

- a time.Duration has no v2 default representation and gives an error.
  FormatDurationAsNano keeps the v1 number of nanoseconds. A struct tag
  would not reach the durations that Metadata holds in an any.
- a struct with no exported field gives an error, so every error in
  Errors failed. A json.MarshalToFunc for error writes the message.
- v2 writes map members in read order. Deterministic keeps the sorted
  order that v1 gave.

MarshalWrite writes no trailing newline, which Encoder.Encode did, so
the export writes one.

Output: the old binary and the new one were run and the bytes compared.
One difference stays, and it is the point of the error marshaler:

    "Errors": [{}]
    "Errors": ["validation warnings: 37/38 records passed"]

A latent difference no run showed: a nil slice now writes [] and a nil
map {}, where v1 wrote null.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Go 1.27 makes UUIDs in the standard library, so UUIDMiddleware no
longer needs github.com/google/uuid. uuid.New() gives a version 4 UUID
in both, and String() gives the same lowercase hex-and-dash form, so
the value in the context does not change.

go mod tidy drops the dependency from the module and from each of the
four example modules.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
- Name: reflect.TypeFor[T]() replaces the zero-length array trick that
  read the package path of T through reflect.TypeOf(z).Elem(). It is
  the same type and the same zero allocations.
- SafeCopy: new(*original), the Go 1.26 form of new, replaces the pair
  of a new(T) and an assignment.

Checked and left alone:

- No helper is superseded by slices, maps, cmp, min or max, and the
  module does not use sort.
- No generic helper exists whose only job is to change an element type,
  so generic methods earn nothing here.
- No struct is embedded, so the field selector in a struct literal
  earns nothing.
- Generalized type inference does not reach a conversion to a generic
  type, so each StepFunc[T](...) in the tests keeps its type argument.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@veggiemonk
veggiemonk merged commit e138ad7 into main Sep 21, 2026
1 check passed
@veggiemonk
veggiemonk deleted the chore/go-modernize branch September 21, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant