refactor: replace manual env overrides with caarlos0/env - #3
Merged
Conversation
⬇️ Go test coverage decreased from 28.5% to 21.5% compared to 206fe28
|
deevus
force-pushed
the
refactor/use-env-parsing
branch
from
February 28, 2026 04:56
7cdac36 to
6e86066
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.
Summary
applyEnv*calls and 4 helper functions withenv.Parse(cfg)fromcaarlos0/env/v11env:"PIXELS_*"struct tags to all config fields with env var overridesTestEmptyEnvDoesNotOverrideDefaultto guard against future library behavior changesDetails
The config loading had ~50 lines of boilerplate wiring each
PIXELS_*env var to its config field via type-specific helpers (applyEnv,applyEnvInt,applyEnvInt64,applyEnvBool).caarlos0/envreplaces all of it with struct tags and a single function call.Chosen over
spf13/viper(heavy deps, key-lowercasing friction) andknadh/koanf(non-mechanical env var naming makesTransformFuncawkward).Preserved behavior:
*boolnil-when-unset semantics (pointer stays nil when env var absent)expandHome,os.ExpandEnvpost-processing unchangedTest plan
go buildcompilesgo test ./...all 11 config tests pass (including env override, provision bool, empty env)go vet ./...clean