12 factor configuration as a typesafe struct in as little as two function calls #golang


Manage your application config as a typesafe struct in as little as two function calls.

https://github.com/JeremyLoy/config

How It Works

Its just simple, pure stdlib.

  • A field’s type determines what strconv function is called.
  • All string conversion rules are as defined in the strconv package
  • If chaining multiple data sources, data sets are merged. Later values override previous values. config.From(“dev.config”).FromEnv().To(&c)
  • Unset values remain as their native zero value
  • Nested structs/subconfigs are delimited with double underscore
    • e.g. PARENT__CHILD
  • Env vars map to struct fields case insensitively
    • NOTE: Also true when using struct tags.

Why you should use this

  • Its the cloud-native way to manage config. See 12 Factor Apps
  • Simple:
    • only 2 lines to configure.
  • Composeable:
    • Merge local files and environment variables for effortless local development.
  • small:
    • only stdlib
    • < 180 LoC

There is no ads to display, Please add some