go-env
go-env copied to clipboard
chore: go 1.23.2 upgrade, README fix, docstring additions, & go styling updates
Purpose
I've contributed to a couple of Netflix OSS projects in the past (weep and consoleme), and wanted to give some TLC to this package to bring it up-to-date with fixes to the README examples, an update to the Go version, and code-style improvements to align with updates to the Go language in recent updates.
Happy to discuss / elaborate on any of my proposals in this change / sidecar scope into separate changes if desired 🙏
Updating the project's Go version
- Updates Go version from
1.22to1.23.2- 1.23 release notes
Readme fixes
- Fixes the currently broken README examples
envimport aliases is redundant, as the import is targeted at the name after the hyphen old source on this behaviour- Adds an explanation for the
requiredlinting that fails when calling the usage example as-is to surface attention around the built-in validation logic - Adds the missing
package mainblock to the second example to allow for simpler copy/pasting into a playground or project - Adopts the more modern conditional var-scoping to the examples
- Ensures the calls to
MarshalandUnmarshalFromEnvirontake pointers to the Environment/Config structs to prevent theErrInvalidValueerror from being returned
Test semantics
- Takes advantage of t.Parallel() to allow unit tests across the project to be run in parallel
Conditional var-scoping
- Takes advantage of flow controls for instances where function call returns are used immediately to simplify how variables are scoped throughout functions and tests
Increased usage of continue
- Updates a number of if-else blocks to simplify them down to an if-contine-block with a subsequent default case
Range over int
- Takes advantage of the new Go language improvements that deprecate the need to write out for loops with
for i := 0; i < 5; i++by simply declaring the integer range to iterate over, ex.for i := range 5
Consts & Docstrings
- Improves docstring coverage in
env.goto provide more clarity into the library / improve switch performance when parsing tags
cc @patricksanders (👋) if you know of the right person to tag here for a review
Hey @sheikhrachel, nice to see you around these parts. Thanks for the PR! I'll take a look.