gitmyhub

viper

Go ★ 30k updated 5mo ago

Go configuration with fangs

A Go library that reads your app's settings from config files, environment variables, and command-line flags and merges them in the correct priority order so you never write custom config-loading code again.

Gosetup: easycomplexity 2/5

Viper is a configuration management library for Go applications (Go is a compiled programming language often used for servers and command-line tools). The problem it solves is that applications need settings — things like a port number, a database address, or an API key — and those settings can come from many different places: a config file, an environment variable, a command-line flag, or a remote configuration server. Without a unified tool, developers end up writing custom code to handle each source separately and decide which one takes priority.

Viper consolidates all of this. You tell it where to look for configuration, and it merges everything together according to a fixed priority order: code-level overrides win first, then command-line flags, then environment variables, then config files, then remote stores, then defaults. It supports config files in JSON, TOML, YAML, INI, envfile, and Java Properties formats. It can also watch a config file for changes while the application is running and automatically reload new values without restarting the server.

You would use Viper when building a Go application that needs flexible configuration — especially if you want it to work both locally (reading a config file) and in cloud environments (reading from environment variables). It is also useful for refactoring because you can create aliases so that renaming a config key does not break existing callers. The library is written in Go and integrates with the Go module system.

Where it fits