Description
Goconfig is an extremely simple configuration library for your Go programs. Make your configuration flags compact and easy to read. Config can be passed as environment var, command line argument, json file or default values.
How to use alternatives and similar packages
Based on the "Configuration" category.
Alternatively, view How to use alternatives based on common mentions on social networks and blogs.
-
kelseyhightower/envconfig
Go library for managing configuration data from environment variables. -
konfig
Composable, observable and performant config handling for Go for the distributed processing era. -
koanf
Light weight, extensible library for reading config in Go applications. Built in support for JSON, TOML, YAML, env, command line. -
confita
Load configuration in cascade from multiple backends into a struct. -
config
JSON or YAML configuration wrapper with environment variables and flags parsing. -
cleanenv
Minimalistic configuration reader (from files, ENV, and wherever you want). -
hjson
Human JSON, a configuration file format for humans. Relaxed syntax, fewer mistakes, more comments. -
gookit/config
application config manage(load,get,set). support JSON, YAML, TOML, INI, HCL. multi file load, data override merge. -
gcfg
read INI-style configuration files into Go structs; supports user-defined types and subsections -
goConfig
Parse a struct as input and populates the fields of this struct with parameters fom command line, environment variables and configuration file. -
joshbetz/config
A small configuration library for Go that parses environment variables, JSON files, and reloads automatically on SIGHUP. -
harvester
Harvester, a easy to use static and dynamic configuration package supportig seeding, env vars and Consul integration. -
onion
Layer based configuration for Go, Supports JSON, TOML, YAML, properties, etcd, env, and encryption using PGP. -
go-aws-ssm
Go package that fetches parameters from AWS System Manager -
configuro
opinionated configuration loading & validation framework from ENV and Files focused towards 12-Factor compliant applications. -
configure
Provides configuration through multiple sources, including JSON, flags and environment variables. -
configuration
Library for initializing configuration structs from env variables, files, flags and 'default' tag. -
go-up
A simple configuration library with recursive placeholders resolution and no magic. -
hocon
Configuration library for working with the HOCON(a human-friendly JSON superset) format, supports features like environment variables, referencing other values, comments and multiple files. -
Genv
Makes it easy to read and use environment variables in your projects -
CONFLATE
Library providing routines to merge and validate JSON, YAML and/or TOML files -
go-ssm-config
Go utility for loading configuration parameters from AWS SSM (Parameter Store). -
sprbox
Build-environment aware toolbox factory and agnostic config parser (YAML, TOML, JSON and Environment vars). -
swap
Instantiate/configure structs recursively, based on build environment. (YAML, TOML, JSON and env). -
typenv
Minimalistic, zero dependency, typed environment variables library. -
gonfig
Tag-based configuration parser which loads values from different providers into typesafe struct. -
nasermirzaei89/env
Simple useful package for read environment variables. -
gone/jconf
Modular JSON configuration. Keep you config structs along the code they configure and delegate parsing to submodules without sacrificing full config serialization. -
txgruppi-config
Quick and easy way to load config files based on a simple set of rules.
Scout APM - Leading-edge performance monitoring starting at $39/month
Do you think we are missing an alternative of How to use or a related project?
README
Goconfig is an extremely simple and powerful configuration library for your Go programs that read values from environment vars, command line arguments and configuration file in JSON.
Make your configuration flags compact and easy to read.
Arguments are parsed from command line with the standard flag
library.
<!-- MarkdownTOC autolink=true bracket=round depth=4 -->
- How to use
- Supported types
- Builtin flags
- [-help](#-help)
- [-config](#-config)
- Contribute
- Testing
- Example project
<!-- /MarkdownTOC -->
How to use
Define your structure with descriptions:
type myconfig struct {
Name string `usage:"The name of something"`
EnableLog bool `usage:"Enable logging into logdb" json:"enable_log"`
MaxProcs int `usage:"Maximum number of procs"`
UsersDB db
LogDB db
}
type db struct {
Host string `usage:"Host where db is located"`
User string `usage:"Database user"`
Pass string `usage:"Database password"`
}
Instance your config with default values:
c := &myconfig{
EnableLog: true,
UsersDB: db{
Host: "localhost",
User: "root",
Pass: "123456",
},
}
Fill your config:
goconfig.Read(c)
How the -help
looks like:
Usage of example:
-enablelog
Enable logging into logdb (default true)
-logdb.host string
Host where db is located (default "localhost")
-logdb.pass string
Database password (default "123456")
-logdb.user string
Database user (default "root")
-maxprocs int
Maximum number of procs
-name string
The name of something
-usersdb.host string
Host where db is located
-usersdb.pass string
Database password
-usersdb.user string
Database user
Supported types
Mainly almost all types from flag
library are supported:
- bool
- float64
- int64
- int
- string
- uint64
- uint
- struct (hyerarchical keys)
- array (any type)
For the moment duration
type is not supported.
Builtin flags
-help
Since flag
library is using the key -help
to show usage, Goconf is behaving
in the same way.
-config
Builtin flag -config
allow read configuration from a file. For the example
configuration above, this is a sample config.json file:
{
"name": "Fulanito",
"usersdb": {
"host": "localhost",
"user": "admin",
"pass": "123"
}
}
Configuration precedence is as follows (higher to lower):
- Arg command line
- Json config file
- Environment variable
- Default value
Contribute
Feel free to fork, make changes and pull-request to master branch.
If you prefer, create a new issue or email me for new features, issues or whatever.
Testing
This command will pass all tests.
make
Example project
This project includes a sample project with a sample configuration. To make the binary:
make example