A Go library for parsing configuration from environment variables into arbitrary structs with flexible naming and defaults.
envconfig is a Go library that parses environment variables into structured Go configuration objects. It automatically maps environment variable names to struct fields, supporting complex types, default values, and custom naming conventions to simplify configuration management in Go applications.
Go developers building applications that follow the 12-factor app methodology or need a clean, type-safe way to manage configuration from environment variables.
Developers choose envconfig for its simplicity, reliability, and production-ready stability—it handles complex nesting and custom types with minimal boilerplate, and has been battle-tested in production for years.
Small library to read your configuration from environment variables
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Maps environment variables to nested struct fields automatically using naming conventions, eliminating manual parsing code as shown in the example with keys like NAME and SHARD_HOST.
Handles underscores at word boundaries and allows custom variable names via struct tags, accommodating various naming styles like CASSANDRA_SSL_CERT from the README.
Supports setting defaults and marking fields as optional through tags, simplifying configuration management with examples like `default=Vincent` and `optional`.
Can parse slices, arrays, and custom types via the Unmarshaler interface, including struct slices with specific formats like `{foobar,9000}` for advanced needs.
The maintainer explicitly states no plans for new features, which may hinder adoption for evolving projects requiring modern configuration capabilities.
Slices and arrays use commas as delimiters with limited configurability, and struct slices require a cumbersome format like `{foobar;localhost:2929}` that can be error-prone.
While it ensures type safety, it lacks integrated validation for value constraints, forcing developers to add extra code for checks like range or format validation.