toml

package module
v0.0.0-...-0591539 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2020 License: MIT Imports: 4 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parser

type Parser struct{}

Parser parses TOML documents.

func New

func New() *Parser

New constructs a new Parser.

func (*Parser) Values

func (p *Parser) Values(src io.ReadCloser) (<-chan func() (string, interface{}), error)

Values parses yaml configuration, iterating over each key value pair and returning them until parsing has been completed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL