Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/BurntSushi/toml
TOML parser for Golang with reflection.
https://github.com/BurntSushi/toml
Last synced: about 1 month ago
JSON representation
TOML parser for Golang with reflection.
- Host: GitHub
- URL: https://github.com/BurntSushi/toml
- Owner: BurntSushi
- License: mit
- Created: 2013-02-26T05:05:48.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2024-05-02T23:39:40.000Z (about 1 month ago)
- Last Synced: 2024-05-03T09:15:43.102Z (about 1 month ago)
- Language: Go
- Homepage:
- Size: 786 KB
- Stars: 4,442
- Watchers: 82
- Forks: 521
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: COPYING
Lists
- awesome-go - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / Markup Languages)
- awesome-go - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / Markup Languages)
- awesome-cobol - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / Middlewares)
- awesome-go-cn - toml
- awesome-go-extra - toml - 02-26T05:05:48Z|2022-08-21T21:54:14Z| (Bot Building / Markup Languages)
- awesome-go-zh - toml
- awesome-go - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / Markup Languages)
- go-awesome - toml - `TOML` 解析&编码包 (开源类库 / 配置)
- awesome-go - toml - TOML configuration format (encoder/decoder with reflection). Stars:`4.4K`. (Text Processing / Markup Languages)
- awesome-go-cn - toml
- fucking-awesome-go - :octocat: toml - TOML configuration format (encoder/decoder with reflection). :star: 900 :fork_and_knife: 140 (Text Processing / Advanced Console UIs)
- awesome-go - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / HTTP Clients)
- awesome-go-projects - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / HTTP Clients)
- awesome-go - toml - | - | - | (Text Processing / HTTP Clients)
- awesome-go - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / Advanced Console UIs)
- awesome-go - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / Markup Languages)
- awesome-go-with-framework - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / HTTP Clients)
- awesome-go - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / Markup Languages)
- zero-alloc-awesome-go - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / Markup Languages)
- awesome-go-stars - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / Markup Languages)
- awesome-go-cn - toml
- awesome-go - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / Advanced Console UIs)
- awesome-go - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / HTTP Clients)
- awesome-stars - BurntSushi/toml - TOML parser for Golang with reflection. (Go)
- awesome-go. - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / Advanced Console UIs)
- awesome-go - toml - TOML configuration format (encoder/decoder with reflection). (<span id="文字处理-text-processing">文字处理 Text Processing</span> / <span id="高级控制台用户界面-advanced-console-uis">高级控制台用户界面 Advanced Console UIs</span>)
- awesome-go-cn - toml - TOML 配置格式 format (encoder/decoder with reflection). (文本处理 / 高级控制台界面)
- awesome-go-with-stars - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / Markup Languages)
- awesome-go - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / HTTP Clients)
- go-awesome - toml - `TOML` 解析&编码包 (开源类库 / 配置)
- repo-1316-awesome-go-cn - toml
- repo-1211-awesome-go-cn - toml
- awesome-Char - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / HTTP Clients)
- awesome-reader - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / HTTP Clients)
- awesome-go - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / HTTP Clients)
- Go-awesome - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / Markup Languages)
- awesome-go-cn - toml
- awesome-go - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / Advanced Console UIs)
- awesome-go - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / Advanced Console UIs)
- go-awesome-cn-star - toml
- awesome-go-zh - toml
- awesome-go-handwritten - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / HTTP Clients)
- awesome-go - toml - TOML 配置格式 format (encoder/decoder with reflection). (文本處理 / 高級控制台界面)
- my-stars - BurntSushi/toml - TOML parser for Golang with reflection. (Go)
- awesome-go - toml - TOML configuration format (encoder/decoder with reflection). - :arrow_down:3913 - :star:1016 (Text Processing / HTTP Clients)
- awesome-go - toml - TOML parser for Golang with reflection. - ★ 2316 (Text Processing)
- go-awesome - toml - `TOML` parsing & encoding package (Open source library / Construction)
- awesome-go2 - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / Advanced Console UIs)
- awesome-go - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / HTTP Clients)
- awesome-go - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / Markup Languages)
- awesome-go - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / Advanced Console UIs)
- awesome-go - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / HTTP Clients)
- awesome-go-cn - toml
- awesome-go - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / Markup Languages)
- awesome-go - toml - TOML configuration format (encoder/decoder with reflection). (Text Processing / Markup Languages)
README
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](https://toml.io/en/v1.0.0).
Documentation: https://godocs.io/github.com/BurntSushi/toml
See the [releases page](https://github.com/BurntSushi/toml/releases) 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:```toml
Age = 25
Cats = [ "Cauchy", "Plato" ]
Pi = 3.14
Perfection = [ 6, 28, 496, 8128 ]
DOB = 1987-07-05T05:45:00Z
```Which can be decoded with:
```go
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:```toml
some_key_NAME = "wat"
``````go
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`:```toml
contacts = [
"Donald Duck ",
"Scrooge McDuck ",
]
```Can be decoded with:
```go
// 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 ",
"Scrooge McDuck ",
]
`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:"[email protected]"}
// &mail.Address{Name:"Scrooge McDuck", Address:"[email protected]"}
}
```To target TOML specifically you can implement `UnmarshalTOML` TOML interface in
a similar way.### More complex usage
See the [`_example/`](/_example) directory for a more complex example.