• Stars
    star
    102
  • Rank 334,347 (Top 7 %)
  • Language
    Go
  • License
    MIT License
  • Created over 11 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

TOML-based config for Go

go-toml-config

Build Status

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.

API documentation

Example

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")

Contributors

Thanks all!

  • @tysonmote
  • @matrixik
  • @fwang2002
  • @shanks
  • @xboston
  • @tgulacsi