go-toml-config is a simple TOML-based
configuration package for Golang apps that allows you to easily load
configuration files and set defaults. It's a simple wrapper around
flag.FlagSet
, so you can use it in pretty much
the same exact way.
With my_app.conf
:
country = "USA"
[atlanta]
enabled = true
population = 432427
temperature = 99.6
Use:
import "github.com/stvp/go-toml-config"
var (
country = config.String("country", "Unknown")
atlantaEnabled = config.Bool("atlanta.enabled", false)
alantaPopulation = config.Int("atlanta.population", 0)
atlantaTemperature = config.Float64("atlanta.temperature", 0)
)
func main() {
config.Parse("/path/to/my_app.conf")
}
You can also create different ConfigSets to manage different logical groupings of config variables:
networkConfig = config.NewConfigSet("network settings", config.ExitOnError)
networkConfig.String("host", "localhost")
networkConfig.Int("port", 8080)
networkConfig.Parse("/path/to/network.conf")
Thanks all!
- @tysonmote
- @matrixik
- @fwang2002
- @shanks
- @xboston
- @tgulacsi