github.com/tfcloud-go/config

Go package for config. Inspired by OpenStack oslo.config library.


Keywords
go, openstack, configuration, oslo, ini-config, tfcloud
License
Apache-2.0
Install
go get github.com/tfcloud-go/config

Documentation

TFCloud Go Config

Go package for config. Inspired by OpenStack oslo.config library.

Usage

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

Copyright

The TFCloud Go Team. Apache License 2.0