|
Name |
|
Date |
Size |
#Lines |
LOC |
| .. | | 03-May-2022 | - |
| .github/ | H | 06-Sep-2021 | - | 115 | 92 |
| benchmark/ | H | 06-Sep-2021 | - | 746 | 643 |
| cmd/ | H | 06-Sep-2021 | - | 643 | 530 |
| query/ | H | 06-Sep-2021 | - | 2,751 | 2,188 |
| .dockerignore | H A D | 06-Sep-2021 | 38 | 3 | 2 |
| .gitignore | H A D | 06-Sep-2021 | 102 | 6 | 5 |
| CONTRIBUTING.md | H A D | 06-Sep-2021 | 4.9 KiB | 133 | 99 |
| Dockerfile | H A D | 06-Sep-2021 | 319 | 12 | 10 |
| LICENSE | H A D | 06-Sep-2021 | 13.1 KiB | 248 | 202 |
| Makefile | H A D | 06-Sep-2021 | 631 | 30 | 22 |
| PULL_REQUEST_TEMPLATE.md | H A D | 06-Sep-2021 | 203 | 6 | 3 |
| README.md | H A D | 06-Sep-2021 | 5.1 KiB | 177 | 126 |
| azure-pipelines.yml | H A D | 06-Sep-2021 | 4.7 KiB | 189 | 184 |
| benchmark.sh | H A D | 06-Sep-2021 | 963 | 36 | 27 |
| doc.go | H A D | 06-Sep-2021 | 789 | 24 | 1 |
| doc_test.go | H A D | 06-Sep-2021 | 3.5 KiB | 171 | 113 |
| example-crlf.toml | H A D | 06-Sep-2021 | 730 | 30 | 23 |
| example.toml | H A D | 06-Sep-2021 | 701 | 30 | 23 |
| fuzz.go | H A D | 06-Sep-2021 | 472 | 32 | 25 |
| fuzz.sh | H A D | 06-Sep-2021 | 291 | 16 | 10 |
| go.mod | H A D | 06-Sep-2021 | 45 | 4 | 2 |
| keysparsing.go | H A D | 06-Sep-2021 | 2.4 KiB | 113 | 97 |
| keysparsing_test.go | H A D | 06-Sep-2021 | 2.1 KiB | 80 | 64 |
| lexer.go | H A D | 06-Sep-2021 | 19.4 KiB | 1,032 | 821 |
| lexer_test.go | H A D | 06-Sep-2021 | 38.4 KiB | 1,248 | 1,124 |
| localtime.go | H A D | 06-Sep-2021 | 9.9 KiB | 288 | 139 |
| localtime_test.go | H A D | 06-Sep-2021 | 12.9 KiB | 457 | 409 |
| marshal.go | H A D | 06-Sep-2021 | 36.3 KiB | 1,309 | 1,038 |
| marshal_OrderPreserve_test.toml | H A D | 06-Sep-2021 | 622 | 40 | 30 |
| marshal_test.go | H A D | 06-Sep-2021 | 94.7 KiB | 4,122 | 3,586 |
| marshal_test.toml | H A D | 06-Sep-2021 | 622 | 40 | 30 |
| parser.go | H A D | 06-Sep-2021 | 12.2 KiB | 509 | 434 |
| parser_test.go | H A D | 06-Sep-2021 | 28.3 KiB | 1,165 | 1,027 |
| position.go | H A D | 06-Sep-2021 | 744 | 30 | 14 |
| position_test.go | H A D | 06-Sep-2021 | 454 | 30 | 23 |
| token.go | H A D | 06-Sep-2021 | 1.9 KiB | 137 | 117 |
| token_test.go | H A D | 06-Sep-2021 | 1.7 KiB | 70 | 64 |
| toml.go | H A D | 06-Sep-2021 | 13.2 KiB | 534 | 419 |
| toml_test.go | H A D | 06-Sep-2021 | 5.6 KiB | 262 | 223 |
| toml_testgen_support_test.go | H A D | 06-Sep-2021 | 2.9 KiB | 118 | 102 |
| toml_testgen_test.go | H A D | 06-Sep-2021 | 21.6 KiB | 929 | 835 |
| tomlpub.go | H A D | 06-Sep-2021 | 1.4 KiB | 72 | 57 |
| tomltree_create.go | H A D | 06-Sep-2021 | 4.4 KiB | 156 | 132 |
| tomltree_create_test.go | H A D | 06-Sep-2021 | 6.3 KiB | 244 | 211 |
| tomltree_write.go | H A D | 06-Sep-2021 | 13.4 KiB | 553 | 469 |
| tomltree_write_test.go | H A D | 06-Sep-2021 | 11.3 KiB | 487 | 426 |
| tomltree_writepub.go | H A D | 06-Sep-2021 | 349 | 7 | 4 |
README.md
1# go-toml
2
3Go library for the [TOML](https://toml.io/) format.
4
5This library supports TOML version
6[v1.0.0-rc.3](https://toml.io/en/v1.0.0-rc.3)
7
8[![Go Reference](https://pkg.go.dev/badge/github.com/pelletier/go-toml.svg)](https://pkg.go.dev/github.com/pelletier/go-toml)
9[![license](https://img.shields.io/github/license/pelletier/go-toml.svg)](https://github.com/pelletier/go-toml/blob/master/LICENSE)
10[![Build Status](https://dev.azure.com/pelletierthomas/go-toml-ci/_apis/build/status/pelletier.go-toml?branchName=master)](https://dev.azure.com/pelletierthomas/go-toml-ci/_build/latest?definitionId=1&branchName=master)
11[![codecov](https://codecov.io/gh/pelletier/go-toml/branch/master/graph/badge.svg)](https://codecov.io/gh/pelletier/go-toml)
12[![Go Report Card](https://goreportcard.com/badge/github.com/pelletier/go-toml)](https://goreportcard.com/report/github.com/pelletier/go-toml)
13[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fpelletier%2Fgo-toml.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fpelletier%2Fgo-toml?ref=badge_shield)
14
15
16## Development status
17
18**ℹ️ Consider go-toml v2!**
19
20The next version of go-toml is in [active development][v2-dev], and
21[nearing completion][v2-map].
22
23Though technically in beta, v2 is already more tested, [fixes bugs][v1-bugs],
24and [much faster][v2-bench]. If you only need reading and writing TOML documents
25(majority of cases), those features are implemented and the API unlikely to
26change.
27
28The remaining features (Document structure editing and tooling) will be added
29shortly. While pull-requests are welcome on v1, no active development is
30expected on it. When v2.0.0 is released, v1 will be deprecated.
31
32 [go-toml v2][v2]
33
34[v2]: https://github.com/pelletier/go-toml/tree/v2
35[v2-map]: https://github.com/pelletier/go-toml/discussions/506
36[v2-dev]: https://github.com/pelletier/go-toml/tree/v2
37[v1-bugs]: https://github.com/pelletier/go-toml/issues?q=is%3Aissue+is%3Aopen+label%3Av2-fixed
38[v2-bench]: https://github.com/pelletier/go-toml/tree/v2#benchmarks
39
40## Features
41
42Go-toml provides the following features for using data parsed from TOML documents:
43
44* Load TOML documents from files and string data
45* Easily navigate TOML structure using Tree
46* Marshaling and unmarshaling to and from data structures
47* Line & column position data for all parsed elements
48* [Query support similar to JSON-Path](query/)
49* Syntax errors contain line and column numbers
50
51## Import
52
53```go
54import "github.com/pelletier/go-toml"
55```
56
57## Usage example
58
59Read a TOML document:
60
61```go
62config, _ := toml.Load(`
63[postgres]
64user = "pelletier"
65password = "mypassword"`)
66// retrieve data directly
67user := config.Get("postgres.user").(string)
68
69// or using an intermediate object
70postgresConfig := config.Get("postgres").(*toml.Tree)
71password := postgresConfig.Get("password").(string)
72```
73
74Or use Unmarshal:
75
76```go
77type Postgres struct {
78 User string
79 Password string
80}
81type Config struct {
82 Postgres Postgres
83}
84
85doc := []byte(`
86[Postgres]
87User = "pelletier"
88Password = "mypassword"`)
89
90config := Config{}
91toml.Unmarshal(doc, &config)
92fmt.Println("user=", config.Postgres.User)
93```
94
95Or use a query:
96
97```go
98// use a query to gather elements without walking the tree
99q, _ := query.Compile("$..[user,password]")
100results := q.Execute(config)
101for ii, item := range results.Values() {
102 fmt.Printf("Query result %d: %v\n", ii, item)
103}
104```
105
106## Documentation
107
108The documentation and additional examples are available at
109[pkg.go.dev](https://pkg.go.dev/github.com/pelletier/go-toml).
110
111## Tools
112
113Go-toml provides three handy command line tools:
114
115* `tomll`: Reads TOML files and lints them.
116
117 ```
118 go install github.com/pelletier/go-toml/cmd/tomll
119 tomll --help
120 ```
121* `tomljson`: Reads a TOML file and outputs its JSON representation.
122
123 ```
124 go install github.com/pelletier/go-toml/cmd/tomljson
125 tomljson --help
126 ```
127
128 * `jsontoml`: Reads a JSON file and outputs a TOML representation.
129
130 ```
131 go install github.com/pelletier/go-toml/cmd/jsontoml
132 jsontoml --help
133 ```
134
135### Docker image
136
137Those tools are also available as a Docker image from
138[dockerhub](https://hub.docker.com/r/pelletier/go-toml). For example, to
139use `tomljson`:
140
141```
142docker run -v $PWD:/workdir pelletier/go-toml tomljson /workdir/example.toml
143```
144
145Only master (`latest`) and tagged versions are published to dockerhub. You
146can build your own image as usual:
147
148```
149docker build -t go-toml .
150```
151
152## Contribute
153
154Feel free to report bugs and patches using GitHub's pull requests system on
155[pelletier/go-toml](https://github.com/pelletier/go-toml). Any feedback would be
156much appreciated!
157
158### Run tests
159
160`go test ./...`
161
162### Fuzzing
163
164The script `./fuzz.sh` is available to
165run [go-fuzz](https://github.com/dvyukov/go-fuzz) on go-toml.
166
167## Versioning
168
169Go-toml follows [Semantic Versioning](http://semver.org/). The supported version
170of [TOML](https://github.com/toml-lang/toml) is indicated at the beginning of
171this document. The last two major versions of Go are supported
172(see [Go Release Policy](https://golang.org/doc/devel/release.html#policy)).
173
174## License
175
176The MIT License (MIT) + Apache 2.0. Read [LICENSE](LICENSE).
177