All Projects → kezhuw → toml

kezhuw / toml

Licence: MIT license
TOML parser and encoder for Go with reflection.

Programming Languages

go
31211 projects - #10 most used programming language

Labels

Projects that are alternatives of or similar to toml

tomlrb
A Racc based TOML parser
Stars: ✭ 63 (+231.58%)
Mutual labels:  toml
coc-toml
Toml extension for coc-nvim, using taplo for lsp engine
Stars: ✭ 52 (+173.68%)
Mutual labels:  toml
rcpptoml
Rcpp Bindings to C++ parser for TOML files
Stars: ✭ 26 (+36.84%)
Mutual labels:  toml
dssg
A static site generator with a different approach
Stars: ✭ 15 (-21.05%)
Mutual labels:  toml
toml-f
TOML parser implementation for data serialization and deserialization in Fortran
Stars: ✭ 69 (+263.16%)
Mutual labels:  toml
generate-awesome
🖨 A command-line tool for generating Awesome Lists from a set of data files.
Stars: ✭ 22 (+15.79%)
Mutual labels:  toml
Cli
A simple, fast, and fun package for building command line apps in Go
Stars: ✭ 16,995 (+89347.37%)
Mutual labels:  toml
remark-frontmatter
remark plugin to support frontmatter (YAML, TOML, and more)
Stars: ✭ 167 (+778.95%)
Mutual labels:  toml
rtoml
A fast TOML library for python implemented in rust.
Stars: ✭ 214 (+1026.32%)
Mutual labels:  toml
tomli
A lil' TOML parser
Stars: ✭ 313 (+1547.37%)
Mutual labels:  toml
version-sync
Keep version numbers in sync with Cargo.toml
Stars: ✭ 65 (+242.11%)
Mutual labels:  toml
wildq
Command-line TOML/JSON/INI/YAML/XML/HCL processor using jq c bindings
Stars: ✭ 22 (+15.79%)
Mutual labels:  toml
config-cpp
C++ Configuration management library inspired by the Viper package for golang.
Stars: ✭ 21 (+10.53%)
Mutual labels:  toml
serdepp
c++ serialize and deserialize adaptor library like rust serde.rs
Stars: ✭ 70 (+268.42%)
Mutual labels:  toml
Boost.toml
header-only C++(98|11|14|17) TOML v0.5.0 parser/encoder depending on Boost
Stars: ✭ 26 (+36.84%)
Mutual labels:  toml
tomlcheck
A syntax checker for TOML files
Stars: ✭ 28 (+47.37%)
Mutual labels:  toml
pp-toml
Paul's Parser for Tom's Own Minimal Language
Stars: ✭ 17 (-10.53%)
Mutual labels:  toml
paerser
No description or website provided.
Stars: ✭ 38 (+100%)
Mutual labels:  toml
demo-myblog
使用Rust、Actix-web和MongoDB构建简单博客网站
Stars: ✭ 40 (+110.53%)
Mutual labels:  toml
llmk
Light LaTeX Make
Stars: ✭ 93 (+389.47%)
Mutual labels:  toml

TOML parser and encoder for Go

Compatible with TOML version v0.4.0.

GoDoc Build Status

Run go get github.com/kezhuw/toml to install.

Examples

Snippets copied from Go test files.

package toml_test

import (
	"fmt"
	"time"

	"github.com/kezhuw/toml"
)

func ExampleUnmarshal_integer() {
	data := []byte(`key = 12345`)
	var out struct{ Key int }

	err := toml.Unmarshal(data, &out)
	if err != nil {
		panic(err)
	}

	fmt.Println(out.Key)
	// Output: 12345
}

func ExampleUnmarshal_datetimeNative() {
	data := []byte(`key = 2016-01-07T15:30:30.123456789Z`)
	var out struct{ Key time.Time }

	err := toml.Unmarshal(data, &out)
	if err != nil {
		panic(err)
	}

	fmt.Println(out.Key.Format(time.RFC3339Nano))
	// Output: 2016-01-07T15:30:30.123456789Z
}

func ExampleUnmarshal_array() {
	data := []byte(`key = [1, 2, 3,4]`)
	var out struct{ Key []int }

	err := toml.Unmarshal(data, &out)
	if err != nil {
		panic(err)
	}

	fmt.Println(out.Key)
	// Output: [1 2 3 4]
}

func ExampleUnmarshal_table() {
	data := []byte(`[key]
	name = "name"
	value = "value"`)
	var out struct {
		Key struct {
			Name  string
			Value string
		}
	}

	err := toml.Unmarshal(data, &out)
	if err != nil {
		panic(err)
	}

	fmt.Printf("key.name = %q\n", out.Key.Name)
	fmt.Printf("key.value = %q\n", out.Key.Value)
	// Output:
	// key.name = "name"
	// key.value = "value"
}

func ExampleUnmarshal_inlineTable() {
	data := []byte(`key = { name = "name", value = "value" }`)
	var out struct {
		Key struct {
			Name  string
			Value string
		}
	}

	err := toml.Unmarshal(data, &out)
	if err != nil {
		panic(err)
	}

	fmt.Printf("key.name = %q\n", out.Key.Name)
	fmt.Printf("key.value = %q\n", out.Key.Value)
	// Output:
	// key.name = "name"
	// key.value = "value"
}

func ExampleUnmarshal_tableArray() {
	data := []byte(`
	[[array]]
	description = "Table In Array"
	`)
	var out struct {
		Array []struct{ Description string }
	}

	err := toml.Unmarshal(data, &out)
	if err != nil {
		panic(err)
	}

	fmt.Println(out.Array[0].Description)
	// Output: Table In Array
}

func ExampleUnmarshal_interface() {
	data := []byte(`key = [1, 2, 3, 4,]`)
	var out struct{ Key interface{} }

	err := toml.Unmarshal(data, &out)
	if err != nil {
		panic(err)
	}

	fmt.Println(out.Key)
	// Output: [1 2 3 4]
}

func ExampleUnmarshal_tagName() {
	data := []byte(`KKKK = "value"`)
	var out struct {
		Key string `toml:"KKKK"`
	}

	err := toml.Unmarshal(data, &out)
	if err != nil {
		panic(err)
	}

	fmt.Println(out.Key)
	// Output: value
}

func ExampleUnmarshal_tagIgnore() {
	data := []byte(`key = "value"`)
	var out struct {
		Key string `toml:"-"`
	}

	err := toml.Unmarshal(data, &out)
	if err != nil {
		panic(err)
	}

	fmt.Println(out.Key)
	// Output:
}

func ExampleUnmarshal_tagString() {
	data := []byte(`key = "12345"`)
	var out struct {
		Key int `toml:",string"`
	}

	err := toml.Unmarshal(data, &out)
	if err != nil {
		panic(err)
	}

	fmt.Println(out.Key)
	// Output: 12345
}

func ExampleUnmarshal_tagOmitempty() {
	data := []byte(``)
	var out struct {
		Key string `toml:",omitempty"`
	}
	out.Key = "Not empty, for now."

	err := toml.Unmarshal(data, &out)
	if err != nil {
		panic(err)
	}

	fmt.Println(out.Key)
	// Output:
}
package toml_test

import (
	"fmt"
	"time"

	"github.com/kezhuw/toml"
)

type duration time.Duration

func (d *duration) UnmarshalText(b []byte) error {
	v, err := time.ParseDuration(string(b))
	if err != nil {
		return err
	}
	*d = duration(v)
	return nil
}

func ExampleUnmarshal_textUnmarshaler() {
	data := []byte(`timeout = "300ms"`)
	var out struct{ Timeout duration }

	err := toml.Unmarshal(data, &out)
	if err != nil {
		panic(err)
	}

	fmt.Println(time.Duration(out.Timeout))
	// Output: 300ms
}

Links

Other TOML libraries written in Go.

License

Released under The MIT License (MIT). See LICENSE for the full license text.

Contribution

Fire issue or pull request if you have any questions.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].