Skip to content

stvp/go-toml-config

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
March 26, 2013 02:48
August 7, 2022 10:45
August 7, 2022 10:58
March 26, 2013 02:30

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

About

TOML-based config for Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages