Skip to content

noodnik2/configurator

Repository files navigation

configurator - golang CLI Configuration Library

Target functionality:

  • Make it easy to load and save application configuration in a file (e.g., $HOME/.config/)
  • Allow configuration value overrides via environment variables
  • Enable a user to create or modify the configuration without a code editor

Statistics

Coverage By File

Requirements

Since configurator uses Generics, go version 1.18 or greater is required.

Usage

Include configurator Into Your Project

$ go get github.com/noodnik2/configurator

Main APIs

  • LoadConfig[T any](configFile string, config *T) error - loads configuration from a file
  • SaveConfig[T any](configFileName string, config T) error - saves configuration to a file
  • EditConfig[T any](config *T) error - invokes a user dialog to set or update the configuration

Second-Level APIs

  • GetConfigEnvItems[T any](config T) ([]ConfigEnvItem, error) - gets a list of configuration items
  • SetConfigEnvItem[T any](config *T, envName, newValueAsString string) error - updates a single configuration item

See the source code for details.

Examples

See example code that uses configurator in the examples sub-folder.

Credits

configurator builds on top of and extends three related foundational libraries:

  • GoDotEnv - sets environment variables from a configuration file
  • Envconfig - populates struct field values based on environment variables
  • promptui - orchestrates a console-based dialog to set / modify configuration values

Caveats