asp, the Automatic Settings Provider, an opinionated companion for viper and cobra.
The cobra package provides excellent command-line flag functionality, and viper provides a rich configuration store and environment variable binding… but… there’s a lot of boilerplate and redundant code if you want to achieve the nirvana of CLI flags and environment variables and configuration file support for all flags/settings in your application. The asp package attempts to reduce this boilerplate by capturing it all from your “canonical” configure structure definition.
The goals of asp are to
-
reduce the redundant boilerplate by concisely defining all of the necessary information in the config struct itself;
-
encourage good practices by ensuring that every option has config, command-line and environment variable representation;
-
avoid possible typos that using string-based configuration lookups can cause—Go can’t tell that
viper.Get("sommeSetting")is misspelled at compile time—but it can tell thatconfig.sommeSettingis invalid if the struct defines the member asconfig.someSetting.