A Go library for loading configuration from environment variables into structs with struct tags and custom decoders.
envconfig is a Go library that automatically loads configuration data from environment variables into Go structs. It solves the problem of manually parsing and validating environment variables by providing a declarative, type-safe approach to configuration management.
Go developers building applications that follow the 12-factor methodology and need a clean, maintainable way to handle environment-based configuration.
Developers choose envconfig for its simplicity, robust struct tag support, and extensibility through custom decoders, reducing boilerplate and ensuring configuration is type-safe and well-organized.
Golang library for managing configuration data 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.
Allows precise control over environment variable mapping, defaults, and validation using tags like `envconfig`, `default`, and `required`, as demonstrated in the struct tag support section with examples for manual overrides and word splitting.
Supports native Go types, slices, maps, durations, and custom decoders via `envconfig.Decoder`, enabling complex configurations without manual parsing, as shown in the examples for maps and custom IP decoding.
Uses embedded structs and prefixes to manage configuration hierarchically and prevent variable collisions, making it ideal for microservices, as highlighted in the prefix management and embedded structs features.
Custom decoders can be implemented for non-standard types, providing flexibility for complex deserialization logic, evidenced by the SMS provider decoder example in the README.
Focuses solely on environment variables; lacks built-in support for other sources like configuration files or command-line arguments, requiring additional libraries or custom code for integration.
Does not support hot reloading; configuration is loaded once at startup, making it unsuitable for applications that need dynamic updates without restarting.
Only validates required fields and type conversion; complex validation rules, such as range checks or regex patterns, must be implemented manually, increasing code complexity.