toml
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:
It also comes with a TOML validator CLI tool:
Examples
For the simplest example, consider some TOML file as just a list of keys and values:
Which can be decoded with:
You can also use struct tags if your struct field name doesn't map to a TOML key value directly:
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
Marshaler
and encoding.TextUnmarshaler
interfacesHere's an example that automatically parses values in a mail.Address
:
Can be decoded with:
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.
Last updated