Having worked with a few projects at optimum already and seeing how gateway has progressed and it's use of the common repo's config package, I really believe we can keep configuration flow and code significantly simpler. For starters, I think there are some annoyances around DevX:
- Defaults can be specified via field tags and directly in types. This means you now have 2x the surface area to keep things in check.
- common/config code has reflect code, is unwieldy and complex to follow; granted its not code that ever really needs to change, but the point remains.
- ENV vars needs to be explicitly defined in field tags, whereas they can be implicitly derived from a single yaml field.
What I think we get right:
- Precedence: env var > flag > config file
- YAML (although I like TOML too)
Proposal
- KISS. Just keep it simple. Define a
Config struct with the appropriate yaml tags.
- Use
validate tag annotations for basic validation.
- Use
koanf to load and parse everything (no need to maintain parsing ourselves -- it has all the parsers we need).
- Config file should be kept by default in
$HOME/.config/<app-name>/config.yaml (as with most CLI tools you'll use today).
A simple and clean example can be seen here: https://github.com/getoptimum/flexnode/blob/main/pkg/config/config.go#L258-L313
- Load from file
- Read ENV var (override)
- Unmarshal with defaults
Having worked with a few projects at optimum already and seeing how gateway has progressed and it's use of the common repo's
configpackage, I really believe we can keep configuration flow and code significantly simpler. For starters, I think there are some annoyances around DevX:What I think we get right:
Proposal
Configstruct with the appropriateyamltags.validatetag annotations for basic validation.koanfto load and parse everything (no need to maintain parsing ourselves -- it has all the parsers we need).$HOME/.config/<app-name>/config.yaml(as with most CLI tools you'll use today).A simple and clean example can be seen here: https://github.com/getoptimum/flexnode/blob/main/pkg/config/config.go#L258-L313