Skip to content

Application Configuration UX #130

Description

@alexanderbez

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions