Create

Sign in to ReadmeX

or

How we handle your data: Privacy Policy

ReadmeX

Your AI reading companion

What would you like to catch up on?

Pick a briefing, or ask your own question.

Your community and people briefings stay personal to you.

viper

viper: A complete configuration solution for Go applications.

What problem it solves

Go applications often need to combine configuration from files, environment variables, command-line flags, remote systems, and application-defined defaults. They also need consistent precedence, typed value access, and the ability to reload configuration without restarting the application.

Key features

  • Multiple configuration sources — Read configuration from files, environment variables, flags, buffers, remote key/value stores, and application-defined defaults. Viper merges these sources into one set of configuration keys and values.

    Source: README

  • Multiple configuration formats — Load configuration files in JSON, TOML, YAML, INI, envfile, or Java Propeties formats. A file without an extension can also be read by specifying its format programmatically.

    Source: README

  • Defined precedence and overrides — Explicit values take precedence over flags, environment variables, configuration files, external key/value stores, and defaults. Defaults and explicit application overrides can be set with dedicated methods.

    Source: README

  • Live configuration updates — Watch configuration files while an application is running and register a callback for changes. Remote key/value stores can also be watched for updated configuration.

    Source: README

  • Typed values and unmarshaling — Retrieve values with generic or type-specific getters, extract configuration subsets, and unmarshal configuration into structs, maps, and embedded structs.

    Source: README

Quick start

Copied verbatim from the project's README.

go get github.com/spf13/viper
// Name of the config file without an extension (Viper will intuit the type
// from an extension on the actual file)
viper.SetConfigName("config")

// Add search paths to find the file
viper.AddConfigPath("/etc/appname/")
viper.AddConfigPath("$HOME/.appname")
viper.AddConfigPath(".")

// Find and read the config file
err := viper.ReadInConfig()

// Handle errors
if err != nil {
	panic(fmt.Errorf("fatal error config file: %w", err))
}

Who it may suit

This may suit Go developers building applications that need configuration from several sources, particularly projects using Cobra or pflag. It may also suit applications that require runtime configuration reloads.

Topics to discuss

  • Which configuration sources and precedence rules should be reconsidered for Viper v2?

  • How should Viper v2 balance new features with backwards compatibility and stability?

  • Which improvements would make configuration discovery, watching, and error handling easier to use?


Written by ReadmeX AI from the project's README, source and public GitHub data; it may contain mistakes.

Read the original README https://github.com/spf13/viper#readme

ReadmeX opened this community for a trending project; it is not run by the project. Maintainers can claim it from the community page.

github.comhttps://github.com/spf13/viper

Comments

…