Go package for config. Inspired by OpenStack oslo.config library.
Install package
go get github.com/tfcloud-go/config
Register configurations
// conf/server.go
package conf
// ...
var CONF = config.CONF
func init() {
group := config.NewOptGroup("server")
CONF.RegisterGroup(group)
host := config.NewStrOpt("host").WithDefault("127.0.0.1")
port := config.NewIntOpt("port").WithDefault(8080)
CONF.RegisterOpts(group, host, port)
}
Parse configurations
// main.go
package main
// ...
var CONF = config.CONF
func main() {
// ...
CONF.ParseFile("your_config_file_name.conf")
// ...
}
Get configuration value
// foo/server.go
package foo
// ...
var CONF = config.CONF
func startServer() {
host := CONF.GetString("server", "host")
port, _ := CONF.GetInt("server", "port")
addr := net.JoinHostPort(host, port)
// ...
}
Use configuration file
foo-server --config your_config_file_name.conf
The TFCloud Go Team. Apache License 2.0