For a configuration loading library for Go applications, the first results are spf13/viper (Viper is the de facto standard Go library for loading configuration from files, environment variables, and command-line flags, covering format flexibility, defaults, live reload, and CLI integration, but it lacks built-in validation, which the search specifically requires), knadh/koanf (koanf is a Go configuration management library that loads settings from files, environment variables, and remote sources with support for YAML/JSON/TOML and automatic hot reloading, though it lacks built-in validation and command-line flag integration) and joho/godotenv (It is a Go configuration library for loading environment variables from dotenv files, which fits the category, but it lacks support for YAML/JSON/TOML, validation, live reload, and CLI flag integration that the search requires). caarlos0/env and gookit/config round out the shortlist. Compare the match explanations and check the project documentation against your requirements.
These libraries provide robust tools for managing application settings, environment variables, and configuration files in Go.
Viper is a configuration management library designed to centralize application settings from diverse sources into a unified, type-safe registry. It aggregates data from local files, environment variables, command-line flags, and remote key-value stores, providing a single source of truth for application state. By utilizing a hierarchical key-value registry, the system resolves configuration values based on a prioritized stack of providers, ranging from default values to runtime overrides. The library distinguishes itself through its pluggable provider abstraction and dynamic update capabiliti
Viper is the de facto standard Go library for loading configuration from files, environment variables, and command-line flags, covering format flexibility, defaults, live reload, and CLI integration, but it lacks built-in validation, which the search specifically requires.
koanf is a configuration management library for Go designed to load, merge, and unmarshal application settings from multiple sources into structured objects. It functions as a multi-source config loader that aggregates data from environment variables, files, and remote providers into a single unified map. The system utilizes a pluggable architecture for parsing and data abstraction, allowing it to transform bytes from formats such as JSON, YAML, and TOML into nested maps. It supports dynamic configuration watching to monitor external sources and trigger automatic reloads when settings change.
koanf is a Go configuration management library that loads settings from files, environment variables, and remote sources with support for YAML/JSON/TOML and automatic hot reloading, though it lacks built-in validation and command-line flag integration.
godotenv is a Go library designed to load, parse, and serialize environment configuration files. It provides tools to extract configuration data from files into maps and inject those key-value pairs directly into the system environment of a Go application process. The project includes a configuration file serializer for exporting environment variable maps back into formatted files and a parser for extracting data without modifying the system environment. It supports injecting variables from strings or files into the process environment using priority-based overloading and overwriting. The li
It is a Go configuration library for loading environment variables from dotenv files, which fits the category, but it lacks support for YAML/JSON/TOML, validation, live reload, and CLI flag integration that the search requires.
env is a Go library that reads environment variables and populates the fields of a Go struct according to tag directives. It uses reflection to iterate over struct types and tags at runtime, mapping environment variable names to struct fields and applying parsing behavior defined in struct tags. The library supports required field validation, returning errors when marked fields are missing or empty after parsing. It also provides default value fallback from struct tags when environment variables are not set, environment variable expansion that recursively substitutes references within values,
env is a Go library that loads configuration specifically from environment variables into structs with defaults and validation, but it does not support file-based config (YAML/JSON/TOML), command-line flags, or live reload, so it covers only part of the requested scope.
📝 Go configuration manage(load,get,set,export). support JSON, YAML, TOML, Properties, INI, HCL, ENV and Flags. Multi file load, data override merge, parse ENV var. Go应用配置加载管理,支持多种格式,多文件加载,远程文件加载,支持数据合并,解析环境变量名
gookit/config is a Go configuration management library that supports loading from multiple formats (YAML, JSON, TOML, and others), environment variables, and command-line flags, directly matching the visitor's need for a Go config loading library.
envconfig is a Go configuration decoder and environment variable mapper that deserializes environment variables into structured Go data types. It provides tools for validating mandatory fields and ensuring application configuration adheres to the external configuration patterns of twelve-factor app compliance. The library features a help generator that creates formatted usage text based on struct definitions to describe expected environment variables. It also includes a validation tool capable of detecting unused environment variables that match a specific prefix but do not correspond to any
This library reads configuration exclusively from environment variables and maps them to Go structs, but it does not load from YAML, JSON, or TOML files, nor does it support command-line flags, live reload, or default values — making it a specialized tool rather than the general-purpose configuration library you asked for.
Cobra is a development framework for building command-line applications in Go. It organizes application logic into a hierarchical tree structure where each node represents a command, complete with its own flags and execution logic. This structure allows developers to build complex, nested command interfaces that mirror business domains while maintaining a clean separation between command orchestration and underlying business logic. The framework distinguishes itself through its declarative approach to metadata and configuration. It automatically derives help documentation, usage instructions,
Cobra is a CLI framework, not a dedicated configuration-loading library — it handles flags and can integrate with external config sources, but its primary purpose is building command-line applications, not loading config from files and environments.
Kong is a declarative command line interface framework and parser for Go. It maps flags and positional arguments directly into typed Go structures using struct tags, allowing developers to define terminal interfaces through data models rather than manual parsing logic. The project functions as a configuration mapper that populates Go structures from a combination of command-line arguments, environment variables, and JSON files. It distinguishes itself by providing a dependency injection container to pass external services into command handlers and a plugin architecture for dynamic command reg
Kong is a declarative CLI framework that maps command-line arguments, environment variables, and JSON files into Go structs, but its core identity is parsing flags and commands rather than being a general-purpose configuration library, and it lacks support for YAML/TOML, validation, and live reload.
This is a framework for building structured terminal applications in Go. It provides the core components necessary to define a command-line interface, including a system for managing commands, sub-commands, and their associated flags. The library distinguishes itself through an automated help generator that produces formatted usage instructions and manual pages, and a shell completion generator that creates tab-completion scripts for Bash, Zsh, Fish, and PowerShell. It also features a command lifecycle manager to handle pre- and post-execution logic and process exit codes. The toolkit covers
This is a Go CLI framework for building command-line applications, not a dedicated configuration-loading library; while it handles flags and environment variables, it does not natively load configuration from files or support validation and hot reload.
Pkl is a configuration-as-code language used to define, validate, and generate structured configuration files. It functions as a type-safe configuration generator that enforces data integrity through a strongly-typed schema, ensuring configuration values meet defined constraints and types during evaluation. The project distinguishes itself by acting as both a configuration file generator and a binding generator. It transforms high-level programmable definitions into static formats such as JSON, YAML, or XML, and produces language-specific source code to synchronize settings and provide type s
Pkl is a configuration-as-code language and generator for producing static config files and bindings, not a Go library that loads configuration from files, environment variables, or other sources at runtime—it lacks environment variable support, live reload, and command-line flag integration, and is written in Java rather than Go.
Dotenv is a Ruby library used for loading key-value pairs from files into an application environment. It includes a configuration parser to extract variables into hashes and a loader to inject those pairs into the global environment. The project features a variable interpolator that resolves environment variables and shell command outputs within configuration values. It also provides a validator to verify that required configuration keys are present during application initialization. The toolset covers environment variable management, including the ability to generate configuration templates
Dotenv is a Ruby library for loading environment variable files, not a Go configuration library; it lacks the multi-format support, live reload, and CLI flag integration this search requires, and its language excludes it from a Go project.
| Repository | Stars | Language | License | Last push |
|---|---|---|---|---|
| spf13/viper | 30.3K | Go | MIT | |
| knadh/koanf | 3.9K | Go | mit | |
| joho/godotenv | 10.5K | Go | MIT | |
| caarlos0/env | 6K | Go | mit | |
| gookit/config | 583 | Go | MIT | |
| kelseyhightower/envconfig | 5.4K | Go | mit | |
| spf13/cobra | 44.1K | Go | Apache-2.0 | |
| alecthomas/kong | 3K | Go | mit | |
| urfave/cli | 24.1K | Go | MIT | |
| apple/pkl | 11.4K | Java | Apache-2.0 |