This parser loads toml
formatted configuration from an io.ReadCloser
.
Click the Playground badge above to see the example running in the Go Playground.
package main
import (
"fmt"
"go.krak3n.codes/gofig"
"go.krak3n.codes/gofig/parsers/toml"
)
type Config struct {
Foo string `gofig:"foo"`
Bar int `gofig:"bar"`
Fizz struct {
Buzz string `gofig:"buzz"`
} `gofig:"fizz"`
}
const blob = `
foo = "bar"
bar = 12
[fizz]
buzz = "fizz"`
func main() {
var cfg Config
// Initialise gofig with the struct config values will be placed into
gfg, err := gofig.New(&cfg)
gofig.Must(err)
// Parse
gofig.Must(gfg.Parse(gofig.FromString(toml.New(), blob)))
fmt.Println(fmt.Sprintf("%+v", cfg))
}