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.
-
koanf
Simple, extremely lightweight, extensible, configuration management library for Go. Support for JSON, TOML, YAML, env, command line, file, S3 etc. Alternative to viper. -
konfig
Composable, observable and performant config handling for Go for the distributed processing era -
gookit/config
📝 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应用配置加载管理,支持多种格式,多文件加载,远程文件加载,支持数据合并,解析环境变量名 -
gcfg
read INI-style configuration files into Go structs; supports user-defined types and subsections -
goConfig
DISCONTINUED. goconfig uses a struct as input and populates the fields of this struct with parameters from command line, environment variables and configuration file. -
joshbetz/config
🛠 A configuration library for Go that parses environment variables, JSON files, and reloads automatically on SIGHUP. -
configuro
An opinionated configuration loading framework for Containerized and Cloud-Native applications. -
hocon
go implementation of lightbend's HOCON configuration library https://github.com/lightbend/config -
configure
Configure is a Go package that gives you easy configuration of your project through redundancy -
Genv
Genv is a library for Go (golang) that makes it easy to read and use environment variables in your projects. It also allows environment variables to be loaded from the .env file. -
swap
Instantiate/configure structs recursively, based on build environment. (YAML, TOML, JSON and env).
InfluxDB - Purpose built for real-time analytics at any scale.
Do you think we are missing an alternative of How to use or a related project?
Popular Comparisons
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