talira

Configuration for Go applications from files, environment variables, flags and remote stores

open sourceMITfree

Viper is a configuration library for Go applications, including 12-factor apps. It reads settings from JSON, TOML, YAML, INI, envfile and Java properties files (finding them across several locations), environment variables, command-line flags, buffers and remote key/value stores such as etcd and Consul, applies defaults and explicit overrides in a fixed order of precedence, and can watch a config file and reload it live. It pairs with Cobra for flags, and supports key aliases and unmarshalling into structs. Its README names Hugo, doctl, Docker Notary, Coder and Vitess among the projects built with it. A v2 is being planned.

Problems it solves

  • load my Go service's settings from a config file but let environment variables override them in production
  • read config from YAML, TOML or JSON in Go without writing my own parsing and merging code
  • reload configuration when the file changes without restarting the Go process
  • combine command-line flags, environment variables and a config file with a clear order of precedence in a Go CLI

Features

  • reads JSON, TOML, YAML, INI, envfile and Java properties config files
  • finds config files across multiple search paths
  • environment variable binding with prefixes
  • command-line flag binding, including Cobra and pflag
  • remote key/value stores such as etcd and Consul
  • defaults and explicit overrides with a fixed precedence order
  • watches config files and reloads them live
  • key aliases for refactoring
  • unmarshals configuration into Go structs

Alternatives

The same job

These do what Viper does.

  1. godotenv Loads environment variables from .env files in Go

Compare Viper with the top 3