Repository navigation
chore: bring the module to Go 1.27 - #4
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brings the module and the four example modules to Go 1.27.
What the machines did
go get go@1.27.0, thenmodernize -fix ./...andgo fix ./...ineach of the five modules. Each directory under
examples/is its ownmodule, so the root pass does not reach them.
int32counter becomes anatomic.Int32slices.Containsreflect.TypeOf(int(0))becomesreflect.TypeFor[int]()The CI workflows read
go-version-file: go.mod, so they follow the newversion with no change.
encoding/json/v2
examples/advancedheld the one JSON site.json.NewEncoder(file)withSetIndentbecomesjson.MarshalWritewithjsontext.WithIndent. Theone
encoding/jsonimport that stays is the v1 options package, aliasedjsonv1.Three v2 defaults needed an option:
time.Durationgives an errorjsonv1.FormatDurationAsNano(true)Metadataholds in anany.json.MarshalToFuncforerrorErrorsfailed. The marshaler writes the message.json.Deterministic(true)MarshalWritewrites no trailing newline, whichEncoder.Encodedid, sothe 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:
A latent difference no run showed: a nil slice now writes
[]and a nilmap
{}, where v1 wrotenull.By hand
uuid. Go 1.27 makes UUIDs in the standard library, soUUIDMiddlewareno longer needsgithub.com/google/uuid. Both give aversion 4 UUID and the same lowercase hex-and-dash string, so the value
in the context does not change.
go mod tidydrops the dependency fromall five modules.
Name.reflect.TypeFor[T]()replaces the zero-length array trickthat read the package path of T through
reflect.TypeOf(z).Elem().Same type, same zero allocations.
SafeCopy.new(*original), the Go 1.26 form ofnew, replacesthe pair of a
new(T)and an assignment.Checked and left alone: no helper is superseded by
slices,maps,cmp,minormax, and the module does not usesort; no generichelper 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 typeargument.
Verification
In all five modules
gofmt -l .,modernize -fix -diff ./...andgo fix -diff ./...print nothing, and build and vet are clean.go test -race -count=1 -shuffle=on ./...passes, the benchmarks run,and
make examplesruns all four examples end to end.🤖 Generated with Claude Code