podman/vendor/github.com/BurntSushi/toml
dependabot[bot] 9457549fff build(deps): bump github.com/vbauerster/mpb/v7 from 7.5.2 to 7.5.3
Bumps [github.com/vbauerster/mpb/v7](https://github.com/vbauerster/mpb) from 7.5.2 to 7.5.3.
- [Release notes](https://github.com/vbauerster/mpb/releases)
- [Commits](https://github.com/vbauerster/mpb/compare/v7.5.2...v7.5.3)

---
updated-dependencies:
- dependency-name: github.com/vbauerster/mpb/v7
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Also bump the go module to 1.17 to be able to compile the new code.
Given containers/common and others already require go 1.17+ we're
safe to go.

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-09-13 08:58:22 +02:00
..
internal Bump github.com/BurntSushi/toml from 0.3.1 to 0.4.1 2021-08-05 12:20:26 +00:00
.gitignore Bump github.com/BurntSushi/toml from 1.1.0 to 1.2.0 2022-07-21 12:11:35 +00:00
COPYING podman-remote.conf enablement 2019-05-30 09:41:17 -05:00
README.md Bump github.com/BurntSushi/toml from 1.1.0 to 1.2.0 2022-07-21 12:11:35 +00:00
decode.go Bump github.com/BurntSushi/toml from 1.1.0 to 1.2.0 2022-07-21 12:11:35 +00:00
decode_go116.go Bump github.com/BurntSushi/toml from 0.4.1 to 1.0.0 2022-01-12 12:09:14 +00:00
deprecated.go Bump github.com/BurntSushi/toml from 0.4.1 to 1.0.0 2022-01-12 12:09:14 +00:00
doc.go Bump github.com/BurntSushi/toml from 0.3.1 to 0.4.1 2021-08-05 12:20:26 +00:00
encode.go Bump github.com/BurntSushi/toml from 1.1.0 to 1.2.0 2022-07-21 12:11:35 +00:00
error.go Bump github.com/BurntSushi/toml from 1.1.0 to 1.2.0 2022-07-21 12:11:35 +00:00
lex.go Bump github.com/BurntSushi/toml from 1.1.0 to 1.2.0 2022-07-21 12:11:35 +00:00
meta.go Bump github.com/BurntSushi/toml from 1.1.0 to 1.2.0 2022-07-21 12:11:35 +00:00
parse.go Bump github.com/BurntSushi/toml from 1.1.0 to 1.2.0 2022-07-21 12:11:35 +00:00
type_fields.go Bump github.com/BurntSushi/toml from 0.4.1 to 1.0.0 2022-01-12 12:09:14 +00:00
type_toml.go Bump github.com/BurntSushi/toml from 0.4.1 to 1.0.0 2022-01-12 12:09:14 +00:00

README.md

TOML stands for Tom's Obvious, Minimal Language. This Go package provides a reflection interface similar to Go's standard library json and xml packages.

Compatible with TOML version v1.0.0.

Documentation: https://godocs.io/github.com/BurntSushi/toml

See the releases page for a changelog; this information is also in the git tag annotations (e.g. git show v0.4.0).

This library requires Go 1.13 or newer; add it to your go.mod with:

% go get github.com/BurntSushi/toml@latest

It also comes with a TOML validator CLI tool:

% go install github.com/BurntSushi/toml/cmd/tomlv@latest
% tomlv some-toml-file.toml

Examples

For the simplest example, consider some TOML file as just a list of keys and values:

Age = 25
Cats = [ "Cauchy", "Plato" ]
Pi = 3.14
Perfection = [ 6, 28, 496, 8128 ]
DOB = 1987-07-05T05:45:00Z

Which can be decoded with:

type Config struct {
	Age        int
	Cats       []string
	Pi         float64
	Perfection []int
	DOB        time.Time
}

var conf Config
_, err := toml.Decode(tomlData, &conf)

You can also use struct tags if your struct field name doesn't map to a TOML key value directly:

some_key_NAME = "wat"
type TOML struct {
    ObscureKey string `toml:"some_key_NAME"`
}

Beware that like other decoders only exported fields are considered when encoding and decoding; private fields are silently ignored.

Using the Marshaler and encoding.TextUnmarshaler interfaces

Here's an example that automatically parses values in a mail.Address:

contacts = [
    "Donald Duck <donald@duckburg.com>",
    "Scrooge McDuck <scrooge@duckburg.com>",
]

Can be decoded with:

// Create address type which satisfies the encoding.TextUnmarshaler interface.
type address struct {
	*mail.Address
}

func (a *address) UnmarshalText(text []byte) error {
	var err error
	a.Address, err = mail.ParseAddress(string(text))
	return err
}

// Decode it.
func decode() {
	blob := `
		contacts = [
			"Donald Duck <donald@duckburg.com>",
			"Scrooge McDuck <scrooge@duckburg.com>",
		]
	`

	var contacts struct {
		Contacts []address
	}

	_, err := toml.Decode(blob, &contacts)
	if err != nil {
		log.Fatal(err)
	}

	for _, c := range contacts.Contacts {
		fmt.Printf("%#v\n", c.Address)
	}

	// Output:
	// &mail.Address{Name:"Donald Duck", Address:"donald@duckburg.com"}
	// &mail.Address{Name:"Scrooge McDuck", Address:"scrooge@duckburg.com"}
}

To target TOML specifically you can implement UnmarshalTOML TOML interface in a similar way.

More complex usage

See the _example/ directory for a more complex example.