Fork of github.com/pelletier/go-toml.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Thomas Pelletier 5b4e7e5dcc
Remove underscore regexps (#448)
3 months ago
.github/ISSUE_TEMPLATE Set up CI with Azure Pipelines (#304) 1 year ago
benchmark Remove date regexp (#447) 3 months ago
cmd Replace CIs by Github Actions (#294) 1 year ago
query Fix query test 8 months ago
.dockerignore Dockerfile (#269) 1 year ago
.gitignore Dockerfile (#269) 1 year ago
CONTRIBUTING.md Port toml-test to pure Go (#264) 1 year ago
Dockerfile jsontoml tool (#296) 1 year ago
LICENSE Update license (#128) 4 years ago
Makefile CI Build Binaries (#345) 10 months ago
PULL_REQUEST_TEMPLATE.md Setup Codecov (#235) 2 years ago
README.md TOML 1.0.0-rc.3 (#449) 3 months ago
azure-pipelines.yml Remove date regexp (#447) 3 months ago
benchmark.sh move benchmark to a seperate diectory (#420) 7 months ago
doc.go TOML 0.5.0 (#320) 1 year ago
doc_test.go marshal: do not encode embedded structs as sub-table (#368) 9 months ago
example-crlf.toml Add float to test case to check leading zeroes in exponent parts (#363) 9 months ago
example.toml Add float to test case to check leading zeroes in exponent parts (#363) 9 months ago
fuzz.go Fix fuzz (#199) 3 years ago
fuzz.sh Add fuzz.sh to do fuzzing with go-fuzz (#194) 3 years ago
go.mod move benchmark to a seperate diectory (#420) 7 months ago
go.sum Remove underscore regexps (#448) 3 months ago
keysparsing.go Fix various quoted keys bugs (#400) 8 months ago
keysparsing_test.go Fix goreportcard issues (#271) 1 year ago
lexer.go Remove date regexp (#447) 3 months ago
lexer_test.go Remove date regexp (#447) 3 months ago
localtime.go Short-date support (#298) 1 year ago
localtime_test.go Short-date support (#298) 1 year ago
marshal.go toml.Unmarshaler supports leaf nodes (#444) 4 months ago
marshal_OrderPreserve_test.toml Fix float64 truncation error (#293) 1 year ago
marshal_test.go toml.Unmarshaler supports leaf nodes (#444) 4 months ago
marshal_test.toml Fix float64 truncation error (#293) 1 year ago
parser.go Remove underscore regexps (#448) 3 months ago
parser_test.go Remove date regexp (#447) 3 months ago
position.go Pointer cleanup (#78) 4 years ago
position_test.go Simplify redundant types in literals (#95) 4 years ago
token.go Remove date regexp (#447) 3 months ago
token_test.go Remove date regexp (#447) 3 months ago
toml.go Fix index exception when setting empty Tree slice (#425) 4 months ago
toml_test.go Added exta tests for GetArrayPath 7 months ago
toml_testgen_support_test.go Port toml-test to pure Go (#264) 1 year ago
toml_testgen_test.go Add support of mixed-type array (#376) 8 months ago
tomltree_create.go Fix TreeFromMap on list of interfaces (#416) 7 months ago
tomltree_create_test.go Fix TreeFromMap on list of interfaces (#416) 7 months ago
tomltree_write.go fix issue#414 7 months ago
tomltree_write_test.go Add float to test case to check leading zeroes in exponent parts (#363) 9 months ago

README.md

go-toml

Go library for the TOML format.

This library supports TOML version v1.0.0-rc.3

GoDoc license Build Status codecov Go Report Card FOSSA Status

Features

Go-toml provides the following features for using data parsed from TOML documents:

  • Load TOML documents from files and string data
  • Easily navigate TOML structure using Tree
  • Marshaling and unmarshaling to and from data structures
  • Line & column position data for all parsed elements
  • Query support similar to JSON-Path
  • Syntax errors contain line and column numbers

Import

import "github.com/pelletier/go-toml"

Usage example

Read a TOML document:

config, _ := toml.Load(`
[postgres]
user = "pelletier"
password = "mypassword"`)
// retrieve data directly
user := config.Get("postgres.user").(string)

// or using an intermediate object
postgresConfig := config.Get("postgres").(*toml.Tree)
password := postgresConfig.Get("password").(string)

Or use Unmarshal:

type Postgres struct {
    User     string
    Password string
}
type Config struct {
    Postgres Postgres
}

doc := []byte(`
[Postgres]
User = "pelletier"
Password = "mypassword"`)

config := Config{}
toml.Unmarshal(doc, &config)
fmt.Println("user=", config.Postgres.User)

Or use a query:

// use a query to gather elements without walking the tree
q, _ := query.Compile("$..[user,password]")
results := q.Execute(config)
for ii, item := range results.Values() {
    fmt.Printf("Query result %d: %v\n", ii, item)
}

Documentation

The documentation and additional examples are available at godoc.org.

Tools

Go-toml provides two handy command line tools:

  • tomll: Reads TOML files and lints them.

    go install github.com/pelletier/go-toml/cmd/tomll
    tomll --help
    
  • tomljson: Reads a TOML file and outputs its JSON representation.

    go install github.com/pelletier/go-toml/cmd/tomljson
    tomljson --help
    
  • jsontoml: Reads a JSON file and outputs a TOML representation.

    go install github.com/pelletier/go-toml/cmd/jsontoml
    jsontoml --help
    

Docker image

Those tools are also availble as a Docker image from dockerhub. For example, to use tomljson:

docker run -v $PWD:/workdir pelletier/go-toml tomljson /workdir/example.toml

Only master (latest) and tagged versions are published to dockerhub. You can build your own image as usual:

docker build -t go-toml .

Contribute

Feel free to report bugs and patches using GitHub's pull requests system on pelletier/go-toml. Any feedback would be much appreciated!

Run tests

go test ./...

Fuzzing

The script ./fuzz.sh is available to run go-fuzz on go-toml.

Versioning

Go-toml follows Semantic Versioning. The supported version of TOML is indicated at the beginning of this document. The last two major versions of Go are supported (see Go Release Policy).

License

The MIT License (MIT). Read LICENSE.