Skip to content

refactor: replace manual env overrides with caarlos0/env - #3

Merged
deevus merged 1 commit into
mainfrom
refactor/use-env-parsing
Feb 28, 2026
Merged

refactor: replace manual env overrides with caarlos0/env#3
deevus merged 1 commit into
mainfrom
refactor/use-env-parsing

Conversation

@deevus

@deevus deevus commented Feb 28, 2026

Copy link
Copy Markdown
Owner

Summary

  • Replace 15 manual applyEnv* calls and 4 helper functions with env.Parse(cfg) from caarlos0/env/v11
  • Add explicit env:"PIXELS_*" struct tags to all config fields with env var overrides
  • Add TestEmptyEnvDoesNotOverrideDefault to guard against future library behavior changes
  • Net -24 lines, zero transitive dependencies added

Details

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/env replaces all of it with struct tags and a single function call.

Chosen over spf13/viper (heavy deps, key-lowercasing friction) and knadh/koanf (non-mechanical env var naming makes TransformFunc awkward).

Preserved behavior:

  • Config priority: TOML defaults < env vars < CLI flags
  • *bool nil-when-unset semantics (pointer stays nil when env var absent)
  • TOML loading, expandHome, os.ExpandEnv post-processing unchanged
  • Error handling improved: invalid env values now surface errors instead of being silently ignored

Test plan

  • go build compiles
  • go test ./... all 11 config tests pass (including env override, provision bool, empty env)
  • go vet ./... clean

@github-actions

github-actions Bot commented Feb 28, 2026

Copy link
Copy Markdown
⬇️ Go test coverage decreased from 28.5% to 21.5% compared to 206fe28
⚠️ 1 of 8 packages have zero coverage.
  • github.com/deevus/pixels

Updated Package Coverages:

# Package Name                             |  Prior |    New
- github.com/deevus/pixels/cmd             |   6.8% |   5.3%
- github.com/deevus/pixels/internal/cache  |  93.8% |  83.3%
- github.com/deevus/pixels/internal/config |  88.9% |  87.1%
- github.com/deevus/pixels/internal/ssh    |  29.3% |  14.7%
View coverage for all packages
# Package Name                              | Coverage
- github.com/deevus/pixels                  |     0.0%
+ github.com/deevus/pixels/cmd              |     5.3%
+ github.com/deevus/pixels/internal/cache   |    83.3%
+ github.com/deevus/pixels/internal/config  |    87.1%
+ github.com/deevus/pixels/internal/dataset |   100.0%
+ github.com/deevus/pixels/internal/egress  |    93.5%
+ github.com/deevus/pixels/internal/ssh     |    14.7%
+ github.com/deevus/pixels/internal/truenas |    68.5%

@deevus
deevus force-pushed the refactor/use-env-parsing branch from 7cdac36 to 6e86066 Compare February 28, 2026 04:56
@deevus
deevus merged commit 8f74409 into main Feb 28, 2026
2 checks passed
@deevus
deevus deleted the refactor/use-env-parsing branch February 28, 2026 04:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant