Repository navigation
Conversation
JeremyLoy
added this pull request to stack #21
October 12, 2026 05:15
cfg, err := config.Load[MyConfig](config.FromEnv()) Load returns a populated T instead of filling a pointer, and returns ErrInvalidTarget rather than panicking when T is not a struct type. To and Sub keep their existing panic for compatibility. Load is a package-level function rather than a Builder method so that the module can keep supporting Go 1.26. Generic methods need Go 1.27; Load can become b.Load[T]() once 1.26 leaves support. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NUxivLjodSESTkzRtdQ4CP
Now that the module requires Go 1.27, Load can be a generic method: cfg, err := config.FromEnv().Load[MyConfig]() This replaces the package-level config.Load[T](b), which existed only to keep supporting Go 1.26. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NUxivLjodSESTkzRtdQ4CP
JeremyLoy
force-pushed
the
feat/generic-load
branch
from
October 12, 2026 05:39
b2d51f3 to
d88a836
Compare
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.
Stack 7/7. Base: #19.
Loadis a generic method onBuilder(generic methods arrived in Go 1.27, which the module requires since #16). It returns a populatedTinstead of filling a pointer you pass in. WhenTis not a struct type, it returnsErrInvalidTargetinstead of panicking.ToandSubkeep their existing panic so current callers see no change.Verification
Test_Loadchecks that a load succeeds, and that on a field error the other fields are still filled in.Test_LoadInvalidTargetchecksintand*struct.ExampleBuilder_Load.gofmt,vetandstaticcheckpass on go1.27.0 and go1.27.2.🤖 Generated with Claude Code
https://claude.ai/code/session_01NUxivLjodSESTkzRtdQ4CP