go-env icon indicating copy to clipboard operation
go-env copied to clipboard

chore: go 1.23.2 upgrade, README fix, docstring additions, & go styling updates

Open sheikhrachel opened this issue 1 year ago • 1 comments

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

Readme fixes

  • Fixes the currently broken README examples
    • env import aliases is redundant, as the import is targeted at the name after the hyphen old source on this behaviour
    • Adds an explanation for the required linting that fails when calling the usage example as-is to surface attention around the built-in validation logic
    • Adds the missing package main block 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 Marshal and UnmarshalFromEnviron take pointers to the Environment/Config structs to prevent the ErrInvalidValue error 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.go to provide more clarity into the library / improve switch performance when parsing tags

sheikhrachel avatar Oct 17 '24 23:10 sheikhrachel

cc @patricksanders (👋) if you know of the right person to tag here for a review

sheikhrachel avatar Oct 17 '24 23:10 sheikhrachel

Hey @sheikhrachel, nice to see you around these parts. Thanks for the PR! I'll take a look.

patricksanders avatar Oct 25 '24 21:10 patricksanders