All Projects → cristalhq → Aconfig

cristalhq / Aconfig

Licence: mit
Simple, useful and opinionated config loader.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Aconfig

Config
A lightweight yet powerful config package for Go projects
Stars: ✭ 126 (-32.62%)
Mutual labels:  config, environment-variables, configuration
Node Convict
Featureful configuration management library for Node.js
Stars: ✭ 1,855 (+891.98%)
Mutual labels:  config, environment-variables, configuration
Environ Config
Python Application Configuration With Environment Variables
Stars: ✭ 210 (+12.3%)
Mutual labels:  config, environment-variables, configuration
Dynaconf
Configuration Management for Python ⚙
Stars: ✭ 2,082 (+1013.37%)
Mutual labels:  config, environment-variables, configuration
Env
Simple lib to parse environment variables to structs
Stars: ✭ 2,164 (+1057.22%)
Mutual labels:  environment-variables, config, configuration
Config
🛠 A configuration library for Go that parses environment variables, JSON files, and reloads automatically on SIGHUP
Stars: ✭ 203 (+8.56%)
Mutual labels:  config, environment-variables, configuration
read-env
🔧 Transform environment variables into JSON object with sanitized values.
Stars: ✭ 60 (-67.91%)
Mutual labels:  config, configuration, environment-variables
sitri
Sitri - powerful settings & configs for python
Stars: ✭ 20 (-89.3%)
Mutual labels:  config, configuration, environment-variables
parse it
A python library for parsing multiple types of config files, envvars & command line arguments that takes the headache out of setting app configurations.
Stars: ✭ 86 (-54.01%)
Mutual labels:  config, configuration, environment-variables
climatecontrol
Python library for loading settings and config data from files and environment variables
Stars: ✭ 20 (-89.3%)
Mutual labels:  config, configuration, environment-variables
superconfig
Access environment variables. Also includes presence validation, type coercion and default values.
Stars: ✭ 33 (-82.35%)
Mutual labels:  config, configuration, environment-variables
env
A lightweight package for loading OS environment variables into structs for Go projects
Stars: ✭ 24 (-87.17%)
Mutual labels:  config, configuration, environment-variables
goodconf
Transparently load variables from environment or JSON/YAML file.
Stars: ✭ 80 (-57.22%)
Mutual labels:  config, configuration, environment-variables
Conf
Go package for loading program configuration from multiple sources.
Stars: ✭ 70 (-62.57%)
Mutual labels:  command-line, environment-variables, configuration
Appconfiguration
Questions, feedback and samples for Azure App Configuration service
Stars: ✭ 116 (-37.97%)
Mutual labels:  config, configuration
Go Config
Robust application configuration made simple
Stars: ✭ 117 (-37.43%)
Mutual labels:  config, configuration
Fsconfig
FsConfig is a F# library for reading configuration data from environment variables and AppSettings with type safety.
Stars: ✭ 108 (-42.25%)
Mutual labels:  environment-variables, configuration
Confl
Config parser for go, modeled after Nginx format, Nice lenient syntax with Comments
Stars: ✭ 127 (-32.09%)
Mutual labels:  config, configuration
Ngx Config
Configuration utility for Angular
Stars: ✭ 135 (-27.81%)
Mutual labels:  config, configuration
Clear Config
Scala FP configuration library with a focus on runtime clarity
Stars: ✭ 108 (-42.25%)
Mutual labels:  config, configuration

aconfig

build-img pkg-img reportcard-img coverage-img

Simple, useful and opinionated config loader.

Rationale

There are many solutions regarding configuration loading in Go. I was looking for a simple loader that will as much as possible and be easy to use and understand. The goal was to load config from 4 places: defaults (in the code), files, environment variables, command-line flags. This library works with all of this sources.

Features

  • Simple API.
  • Clean and tested code.
  • Automatic fields mapping.
  • Supports different sources:
    • defaults in the code
    • files (JSON, YAML, TOML, DotENV, HCL)
    • environment variables
    • command-line flags
  • Dependency-free (file parsers are optional).
  • Ability to walk over configuration fields.

Install

Go version 1.14+

go get github.com/cristalhq/aconfig

Example

type MyConfig struct {
	Port int `default:"1111" usage:"just give a number"`
	Auth struct {
		User string `default:"def-user"`
		Pass string `default:"def-pass"`
	}
	Pass string `default:"" env:"SECRET" flag:"sec_ret"`
}

var cfg MyConfig
loader := aconfig.LoaderFor(&cfg, aconfig.Config{
	// feel free to skip some steps :)
	// SkipDefaults: true,
	// SkipFiles:    true,
	// SkipEnv:      true,
	// SkipFlags:    true,
	EnvPrefix:       "APP",
	FlagPrefix:      "app",
	Files:           []string{"/var/opt/myapp/config.json", "ouch.yaml"},
	FileDecoders: map[string]aconfig.FileDecoder{
		// from `aconfigyaml` submodule
		// see submodules in repo for more formats
		".yaml": aconfigyaml.New(),
	},
})

// IMPORTANT: define your own flags with `flagSet`
flagSet := loader.Flags()

if err := loader.Load(); err != nil {
	panic(err)
}

// configuration fields will be loaded from (in order):
//
// 1. defaults set in structure tags (see MyConfig defenition)
// 2. loaded from files `file.json` if not `ouch.yaml` will be used
// 3. from corresponding environment variables with the prefix `APP_`
// 4. command-line flags with the prefix `app.` if they are 

Also see examples: examples_test.go.

Integration with spf13/cobra playground.

Documentation

See these docs.

License

MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].