Skip to content

Latest commit

 

History

History

toml

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

TOML Parser

Go Version Example Documentation Workflow Status

This parser loads toml formatted configuration from an io.ReadCloser.

Example

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