Koanf loads and merges application settings from files, flags, environment variables, Vault, S3, and other sources with pluggable parsers for JSON, YAML, TOML, and more.
Overview
Koanf is a Go library for reading configuration from many sources and formats behind small Provider and Parser interfaces. Providers supply raw bytes or nested maps; parsers turn serialized data into nested map structures that koanf loads and merges.
Bundled providers cover local files, environment variables, command-line flags (stdlib flag and spf13/pflag), maps and structs, raw bytes, S3, Hashicorp Vault, Consul, etcd, AWS AppConfig, Parameter Store, GCP Secret Manager, and other backends. Optional modules install separately so the core stays small. Bundled parsers include JSON, JSONC, YAML, TOML, dotenv, HJSON, HUML, and NestedText.
Multiple loads merge in caller-defined order with delimiter-based key paths such as app.server.port. Some providers can watch for changes and trigger reload callbacks. Values unmarshalling into structs, custom merge strategies, strict merge mode, and flat-path unmarshalling are supported for advanced setups.
The authors position koanf as a lighter alternative to spf13/viper, with clearer abstractions, fewer default dependencies, and without viper’s fixed ordering between flag, env, and file sources.
Key features
- Pluggable config providers
- JSON, YAML, and TOML parsers
- Merge from multiple sources
- Delimited key path lookup
- Env and CLI flag providers
- Vault, S3, and Consul backends
- Struct unmarshalling and custom merges
- Optional file watch reload
Use cases
- Layer file, env, and flag settings
- Load secrets from Vault or cloud stores
- Replace viper in Go services
- Watch config files for hot reload