Go library for the TOML language

go-toml

Go library for the TOML format.

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

Go Reference 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 pkg.go.dev.

Tools

Go-toml provides three 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.

Comments
  • MapFromTree(t *TomlTree) map[string]interface{} ?

    MapFromTree(t *TomlTree) map[string]interface{} ?

    Would you consider it? Maybe it is there and I'm still missing it. I see TreeFromMap() but actually need the reverse, a clean map. From looking at the code there is enough use of custom structs that stripping them all down to bare Go types might be daunting. I like having the syntax specific errors during the parsing, but then need a very generic map. Writing it now and can submit a PR with the additional function perhaps eventually (since I have to have it either way). Feedback appreciated.

  • Powerful querying interface

    Powerful querying interface

    As pointed out by @eanderton in https://github.com/pelletier/go-toml/pull/21#issuecomment-53159667, it would be great to implement a powerful way to query the tree structure.

    Possible ideas:

    Thoughts, ideas and suggestions are welcome!

  • Decode: validate dates

    Decode: validate dates

    Issue: #613

    Constructs a datestring with RFC3339 formatting using the parsed date values, then attempts to call time.Parse() on it, which returns a non-nil error if datetime string was invalid or time's parsing of the string failed.

    Fixes go test -tags testsuite -run TestTOMLTest_Invalid_Datetime_ImpossibleDate failure.

  • Fix tomltestgen failing tests

    Fix tomltestgen failing tests

    After merging https://github.com/pelletier/go-toml/pull/610 the toml-test generated tests have been disabled from automatic build because some tests are failing.

    This issue tracks fixing the failing tests and ultimately make the toml-test generated tests part of the regular build again.

    For new comers, a lot of those issues are corner cases that should be easy to tackle. Feel free to create a pull request for any of them!

    Make sure to remove the Skip() call of the test you're trying to fix in the PR.

    Tests results

    $ echo -e "Status at $(git rev-parse HEAD):\n" && go test -tags testsuite -v -run TestTOML|grep -a -E "(PASS|SKIP):" |sed -E 's/.+(PASS|SKIP): (.+) .+/- [\1] `go test -run \2`/'|sed 's/PASS/x/'|sed 's/SKIP/ /'
    

    Status at 39f893ad996ceacf498c891243955393a8382723:

    • [x] go test -run TestTOMLTest_Invalid_Array_MissingSeparator
    • [x] go test -run TestTOMLTest_Invalid_Array_NoClose2
    • [x] go test -run TestTOMLTest_Invalid_Array_NoCloseTable2
    • [x] go test -run TestTOMLTest_Invalid_Array_NoCloseTable
    • [x] go test -run TestTOMLTest_Invalid_Array_NoClose
    • [x] go test -run TestTOMLTest_Invalid_Array_Tables1
    • [x] go test -run TestTOMLTest_Invalid_Array_Tables2
    • [x] go test -run TestTOMLTest_Invalid_Array_TextAfterArrayEntries
    • [x] go test -run TestTOMLTest_Invalid_Array_TextBeforeArraySeparator
    • [x] go test -run TestTOMLTest_Invalid_Array_TextInArray
    • [x] go test -run TestTOMLTest_Invalid_Bool_MixedCase
    • [x] go test -run TestTOMLTest_Invalid_Bool_WrongCaseFalse
    • [x] go test -run TestTOMLTest_Invalid_Bool_WrongCaseTrue
    • [x] go test -run TestTOMLTest_Invalid_Control_CommentDel
    • [x] go test -run TestTOMLTest_Invalid_Control_CommentLf
    • [x] go test -run TestTOMLTest_Invalid_Control_CommentNull
    • [x] go test -run TestTOMLTest_Invalid_Control_CommentUs
    • [x] go test -run TestTOMLTest_Invalid_Control_MultiDel
    • [x] go test -run TestTOMLTest_Invalid_Control_MultiLf
    • [x] go test -run TestTOMLTest_Invalid_Control_MultiNull
    • [x] go test -run TestTOMLTest_Invalid_Control_MultiUs
    • [x] go test -run TestTOMLTest_Invalid_Control_RawmultiDel
    • [x] go test -run TestTOMLTest_Invalid_Control_RawmultiLf
    • [x] go test -run TestTOMLTest_Invalid_Control_RawmultiNull
    • [x] go test -run TestTOMLTest_Invalid_Control_RawmultiUs
    • [x] go test -run TestTOMLTest_Invalid_Control_RawstringDel
    • [x] go test -run TestTOMLTest_Invalid_Control_RawstringLf
    • [x] go test -run TestTOMLTest_Invalid_Control_RawstringNull
    • [x] go test -run TestTOMLTest_Invalid_Control_RawstringUs
    • [x] go test -run TestTOMLTest_Invalid_Control_StringBs
    • [x] go test -run TestTOMLTest_Invalid_Control_StringDel
    • [x] go test -run TestTOMLTest_Invalid_Control_StringLf
    • [x] go test -run TestTOMLTest_Invalid_Control_StringNull
    • [x] go test -run TestTOMLTest_Invalid_Control_StringUs
    • [x] go test -run TestTOMLTest_Invalid_Datetime_ImpossibleDate
    • [x] go test -run TestTOMLTest_Invalid_Datetime_NoLeadsWithMilli
    • [x] go test -run TestTOMLTest_Invalid_Datetime_NoLeads
    • [x] go test -run TestTOMLTest_Invalid_Datetime_NoSecs
    • [x] go test -run TestTOMLTest_Invalid_Datetime_NoT
    • [x] go test -run TestTOMLTest_Invalid_Datetime_TrailingT
    • [x] go test -run TestTOMLTest_Invalid_Encoding_BadUtf8AtEnd
    • [x] go test -run TestTOMLTest_Invalid_Encoding_BadUtf8InComment
    • [x] go test -run TestTOMLTest_Invalid_Encoding_BadUtf8InString
    • [x] go test -run TestTOMLTest_Invalid_Encoding_BomNotAtStart1
    • [x] go test -run TestTOMLTest_Invalid_Encoding_BomNotAtStart2
    • [x] go test -run TestTOMLTest_Invalid_Encoding_Utf16Bom
    • [x] go test -run TestTOMLTest_Invalid_Encoding_Utf16
    • [x] go test -run TestTOMLTest_Invalid_Float_DoublePoint1
    • [x] go test -run TestTOMLTest_Invalid_Float_DoublePoint2
    • [x] go test -run TestTOMLTest_Invalid_Float_ExpDoubleE1
    • [x] go test -run TestTOMLTest_Invalid_Float_ExpDoubleE2
    • [x] go test -run TestTOMLTest_Invalid_Float_ExpDoubleUs
    • [x] go test -run TestTOMLTest_Invalid_Float_ExpLeadingUs
    • [x] go test -run TestTOMLTest_Invalid_Float_ExpPoint1
    • [x] go test -run TestTOMLTest_Invalid_Float_ExpPoint2
    • [x] go test -run TestTOMLTest_Invalid_Float_ExpTrailingUs
    • [x] go test -run TestTOMLTest_Invalid_Float_InfIncomplete1
    • [x] go test -run TestTOMLTest_Invalid_Float_InfIncomplete2
    • [x] go test -run TestTOMLTest_Invalid_Float_InfIncomplete3
    • [x] go test -run TestTOMLTest_Invalid_Float_Inf_underscore
    • [x] go test -run TestTOMLTest_Invalid_Float_LeadingPointNeg
    • [x] go test -run TestTOMLTest_Invalid_Float_LeadingPointPlus
    • [x] go test -run TestTOMLTest_Invalid_Float_LeadingPoint
    • [x] go test -run TestTOMLTest_Invalid_Float_LeadingUs
    • [x] go test -run TestTOMLTest_Invalid_Float_LeadingZeroNeg
    • [x] go test -run TestTOMLTest_Invalid_Float_LeadingZeroPlus
    • [x] go test -run TestTOMLTest_Invalid_Float_LeadingZero
    • [x] go test -run TestTOMLTest_Invalid_Float_NanIncomplete1
    • [x] go test -run TestTOMLTest_Invalid_Float_NanIncomplete2
    • [x] go test -run TestTOMLTest_Invalid_Float_NanIncomplete3
    • [x] go test -run TestTOMLTest_Invalid_Float_Nan_underscore
    • [x] go test -run TestTOMLTest_Invalid_Float_TrailingPointMin
    • [x] go test -run TestTOMLTest_Invalid_Float_TrailingPointPlus
    • [x] go test -run TestTOMLTest_Invalid_Float_TrailingPoint
    • [x] go test -run TestTOMLTest_Invalid_Float_TrailingUs
    • [x] go test -run TestTOMLTest_Invalid_Float_UsAfterPoint
    • [x] go test -run TestTOMLTest_Invalid_Float_UsBeforePoint
    • [x] go test -run TestTOMLTest_Invalid_InlineTable_DoubleComma
    • [x] go test -run TestTOMLTest_Invalid_InlineTable_Empty
    • [x] go test -run TestTOMLTest_Invalid_InlineTable_Linebreak1
    • [x] go test -run TestTOMLTest_Invalid_InlineTable_Linebreak2
    • [x] go test -run TestTOMLTest_Invalid_InlineTable_Linebreak3
    • [x] go test -run TestTOMLTest_Invalid_InlineTable_Linebreak4
    • [x] go test -run TestTOMLTest_Invalid_InlineTable_NoComma
    • [x] go test -run TestTOMLTest_Invalid_InlineTable_TrailingComma
    • [x] go test -run TestTOMLTest_Invalid_Integer_CapitalBin
    • [x] go test -run TestTOMLTest_Invalid_Integer_CapitalHex
    • [x] go test -run TestTOMLTest_Invalid_Integer_CapitalOct
    • [x] go test -run TestTOMLTest_Invalid_Integer_DoubleSignNex
    • [x] go test -run TestTOMLTest_Invalid_Integer_DoubleSignPlus
    • [x] go test -run TestTOMLTest_Invalid_Integer_DoubleUs
    • [x] go test -run TestTOMLTest_Invalid_Integer_InvalidBin
    • [x] go test -run TestTOMLTest_Invalid_Integer_InvalidHex
    • [x] go test -run TestTOMLTest_Invalid_Integer_InvalidOct
    • [x] go test -run TestTOMLTest_Invalid_Integer_LeadingUsBin
    • [x] go test -run TestTOMLTest_Invalid_Integer_LeadingUsHex
    • [x] go test -run TestTOMLTest_Invalid_Integer_LeadingUsOct
    • [x] go test -run TestTOMLTest_Invalid_Integer_LeadingUs
    • [x] go test -run TestTOMLTest_Invalid_Integer_LeadingZero1
    • [x] go test -run TestTOMLTest_Invalid_Integer_LeadingZero2
    • [x] go test -run TestTOMLTest_Invalid_Integer_LeadingZeroSign1
    • [x] go test -run TestTOMLTest_Invalid_Integer_LeadingZeroSign2
    • [x] go test -run TestTOMLTest_Invalid_Integer_NegativeBin
    • [x] go test -run TestTOMLTest_Invalid_Integer_NegativeHex
    • [x] go test -run TestTOMLTest_Invalid_Integer_NegativeOct
    • [x] go test -run TestTOMLTest_Invalid_Integer_PositiveBin
    • [x] go test -run TestTOMLTest_Invalid_Integer_PositiveHex
    • [x] go test -run TestTOMLTest_Invalid_Integer_PositiveOct
    • [x] go test -run TestTOMLTest_Invalid_Integer_TextAfterInteger
    • [x] go test -run TestTOMLTest_Invalid_Integer_TrailingUsBin
    • [x] go test -run TestTOMLTest_Invalid_Integer_TrailingUsHex
    • [x] go test -run TestTOMLTest_Invalid_Integer_TrailingUsOct
    • [x] go test -run TestTOMLTest_Invalid_Integer_TrailingUs
    • [x] go test -run TestTOMLTest_Invalid_Integer_UsAfterBin
    • [x] go test -run TestTOMLTest_Invalid_Integer_UsAfterHex
    • [x] go test -run TestTOMLTest_Invalid_Integer_UsAfterOct
    • [x] go test -run TestTOMLTest_Invalid_Key_AfterArray
    • [x] go test -run TestTOMLTest_Invalid_Key_AfterTable
    • [x] go test -run TestTOMLTest_Invalid_Key_AfterValue
    • [x] go test -run TestTOMLTest_Invalid_Key_BareInvalidCharacter
    • [x] go test -run TestTOMLTest_Invalid_Key_DottedRedefineTable
    • [x] go test -run TestTOMLTest_Invalid_Key_DuplicateKeys
    • [x] go test -run TestTOMLTest_Invalid_Key_Duplicate
    • [x] go test -run TestTOMLTest_Invalid_Key_Empty
    • [x] go test -run TestTOMLTest_Invalid_Key_Escape
    • [x] go test -run TestTOMLTest_Invalid_Key_Hash
    • [x] go test -run TestTOMLTest_Invalid_Key_Multiline
    • [x] go test -run TestTOMLTest_Invalid_Key_Newline
    • [x] go test -run TestTOMLTest_Invalid_Key_NoEol
    • [x] go test -run TestTOMLTest_Invalid_Key_OpenBracket
    • [x] go test -run TestTOMLTest_Invalid_Key_PartialQuoted
    • [x] go test -run TestTOMLTest_Invalid_Key_SingleOpenBracket
    • [x] go test -run TestTOMLTest_Invalid_Key_Space
    • [x] go test -run TestTOMLTest_Invalid_Key_SpecialCharacter
    • [x] go test -run TestTOMLTest_Invalid_Key_StartBracket
    • [x] go test -run TestTOMLTest_Invalid_Key_TwoEquals
    • [x] go test -run TestTOMLTest_Invalid_Key_TwoEquals2
    • [x] go test -run TestTOMLTest_Invalid_Key_TwoEquals3
    • [x] go test -run TestTOMLTest_Invalid_Key_WithoutValue1
    • [x] go test -run TestTOMLTest_Invalid_Key_WithoutValue2
    • [x] go test -run TestTOMLTest_Invalid_String_BadByteEscape
    • [x] go test -run TestTOMLTest_Invalid_String_BadCodepoint
    • [x] go test -run TestTOMLTest_Invalid_String_BadConcat
    • [x] go test -run TestTOMLTest_Invalid_String_BadEscape
    • [x] go test -run TestTOMLTest_Invalid_String_BadMultiline
    • [x] go test -run TestTOMLTest_Invalid_String_BadSlashEscape
    • [x] go test -run TestTOMLTest_Invalid_String_BadUniEsc
    • [x] go test -run TestTOMLTest_Invalid_String_BasicByteEscapes
    • [x] go test -run TestTOMLTest_Invalid_String_BasicMultilineOutOfRangeUnicodeEscape1
    • [x] go test -run TestTOMLTest_Invalid_String_BasicMultilineOutOfRangeUnicodeEscape2
    • [x] go test -run TestTOMLTest_Invalid_String_BasicMultilineQuotes
    • [x] go test -run TestTOMLTest_Invalid_String_BasicMultilineUnknownEscape
    • [x] go test -run TestTOMLTest_Invalid_String_BasicOutOfRangeUnicodeEscape1
    • [x] go test -run TestTOMLTest_Invalid_String_BasicOutOfRangeUnicodeEscape2
    • [x] go test -run TestTOMLTest_Invalid_String_BasicUnknownEscape
    • [x] go test -run TestTOMLTest_Invalid_String_LiteralMultilineQuotes1
    • [x] go test -run TestTOMLTest_Invalid_String_LiteralMultilineQuotes2
    • [x] go test -run TestTOMLTest_Invalid_String_MissingQuotes
    • [x] go test -run TestTOMLTest_Invalid_String_MultilineEscapeSpace
    • [x] go test -run TestTOMLTest_Invalid_String_MultilineNoClose2
    • [x] go test -run TestTOMLTest_Invalid_String_MultilineNoClose
    • [x] go test -run TestTOMLTest_Invalid_String_MultilineQuotes1
    • [x] go test -run TestTOMLTest_Invalid_String_MultilineQuotes2
    • [x] go test -run TestTOMLTest_Invalid_String_NoClose
    • [x] go test -run TestTOMLTest_Invalid_String_TextAfterString
    • [x] go test -run TestTOMLTest_Invalid_String_WrongClose
    • [x] go test -run TestTOMLTest_Invalid_Table_ArrayEmpty
    • [x] go test -run TestTOMLTest_Invalid_Table_ArrayImplicit
    • [x] go test -run TestTOMLTest_Invalid_Table_ArrayMissingBracket
    • [x] go test -run TestTOMLTest_Invalid_Table_DuplicateKeyTable
    • [x] go test -run TestTOMLTest_Invalid_Table_DuplicateTableArray
    • [x] go test -run TestTOMLTest_Invalid_Table_DuplicateTableArray2
    • [x] go test -run TestTOMLTest_Invalid_Table_Duplicate
    • [x] go test -run TestTOMLTest_Invalid_Table_EmptyImplicitTable
    • [x] go test -run TestTOMLTest_Invalid_Table_Empty
    • [x] go test -run TestTOMLTest_Invalid_Table_EqualsSign
    • [x] go test -run TestTOMLTest_Invalid_Table_Injection1
    • [x] go test -run TestTOMLTest_Invalid_Table_Injection2
    • [x] go test -run TestTOMLTest_Invalid_Table_Llbrace
    • [x] go test -run TestTOMLTest_Invalid_Table_NestedBracketsClose
    • [x] go test -run TestTOMLTest_Invalid_Table_NestedBracketsOpen
    • [x] go test -run TestTOMLTest_Invalid_Table_QuotedNoClose
    • [x] go test -run TestTOMLTest_Invalid_Table_Redefine
    • [x] go test -run TestTOMLTest_Invalid_Table_Rrbrace
    • [x] go test -run TestTOMLTest_Invalid_Table_TextAfterTable
    • [x] go test -run TestTOMLTest_Invalid_Table_Whitespace
    • [x] go test -run TestTOMLTest_Invalid_Table_WithPound
    • [x] go test -run TestTOMLTest_Valid_Array_Array
    • [x] go test -run TestTOMLTest_Valid_Array_Bool
    • [x] go test -run TestTOMLTest_Valid_Array_Empty
    • [x] go test -run TestTOMLTest_Valid_Array_Hetergeneous
    • [x] go test -run TestTOMLTest_Valid_Array_MixedIntArray
    • [x] go test -run TestTOMLTest_Valid_Array_MixedIntFloat
    • [x] go test -run TestTOMLTest_Valid_Array_MixedIntString
    • [x] go test -run TestTOMLTest_Valid_Array_MixedStringTable
    • [x] go test -run TestTOMLTest_Valid_Array_NestedDouble
    • [x] go test -run TestTOMLTest_Valid_Array_NestedInlineTable
    • [x] go test -run TestTOMLTest_Valid_Array_Nested
    • [x] go test -run TestTOMLTest_Valid_Array_Nospaces
    • [x] go test -run TestTOMLTest_Valid_Array_StringQuoteComma2
    • [x] go test -run TestTOMLTest_Valid_Array_StringQuoteComma
    • [x] go test -run TestTOMLTest_Valid_Array_StringWithComma
    • [x] go test -run TestTOMLTest_Valid_Array_Strings
    • [x] go test -run TestTOMLTest_Valid_Array_TableArrayStringBackslash
    • [x] go test -run TestTOMLTest_Valid_Bool_Bool
    • [x] go test -run TestTOMLTest_Valid_Comment_AtEof
    • [x] go test -run TestTOMLTest_Valid_Comment_AtEof2
    • [x] go test -run TestTOMLTest_Valid_Comment_Everywhere
    • [x] go test -run TestTOMLTest_Valid_Comment_Tricky
    • [x] go test -run TestTOMLTest_Valid_Datetime_Datetime
    • [x] go test -run TestTOMLTest_Valid_Datetime_LocalDate
    • [x] go test -run TestTOMLTest_Valid_Datetime_LocalTime
    • [x] go test -run TestTOMLTest_Valid_Datetime_Local
    • [x] go test -run TestTOMLTest_Valid_Datetime_Milliseconds
    • [x] go test -run TestTOMLTest_Valid_Datetime_Timezone
    • [x] go test -run TestTOMLTest_Valid_EmptyFile
    • [x] go test -run TestTOMLTest_Valid_Example
    • [x] go test -run TestTOMLTest_Valid_Float_Exponent
    • [x] go test -run TestTOMLTest_Valid_Float_Float
    • [x] go test -run TestTOMLTest_Valid_Float_InfAndNan
    • [x] go test -run TestTOMLTest_Valid_Float_Long
    • [x] go test -run TestTOMLTest_Valid_Float_Underscore
    • [x] go test -run TestTOMLTest_Valid_Float_Zero
    • [x] go test -run TestTOMLTest_Valid_ImplicitAndExplicitAfter
    • [x] go test -run TestTOMLTest_Valid_ImplicitAndExplicitBefore
    • [x] go test -run TestTOMLTest_Valid_ImplicitGroups
    • [x] go test -run TestTOMLTest_Valid_InlineTable_Array
    • [x] go test -run TestTOMLTest_Valid_InlineTable_Bool
    • [x] go test -run TestTOMLTest_Valid_InlineTable_Empty
    • [x] go test -run TestTOMLTest_Valid_InlineTable_EndInBool
    • [x] go test -run TestTOMLTest_Valid_InlineTable_InlineTable
    • [x] go test -run TestTOMLTest_Valid_InlineTable_KeyDotted
    • [x] go test -run TestTOMLTest_Valid_InlineTable_Multiline
    • [x] go test -run TestTOMLTest_Valid_InlineTable_Nest
    • [x] go test -run TestTOMLTest_Valid_Integer_Integer
    • [x] go test -run TestTOMLTest_Valid_Integer_Literals
    • [x] go test -run TestTOMLTest_Valid_Integer_Long
    • [x] go test -run TestTOMLTest_Valid_Integer_Underscore
    • [x] go test -run TestTOMLTest_Valid_Integer_Zero
    • [x] go test -run TestTOMLTest_Valid_Key_Alphanum
    • [x] go test -run TestTOMLTest_Valid_Key_CaseSensitive
    • [x] go test -run TestTOMLTest_Valid_Key_Dotted
    • [x] go test -run TestTOMLTest_Valid_Key_Empty
    • [x] go test -run TestTOMLTest_Valid_Key_EqualsNospace
    • [x] go test -run TestTOMLTest_Valid_Key_Escapes
    • [x] go test -run TestTOMLTest_Valid_Key_NumericDotted
    • [x] go test -run TestTOMLTest_Valid_Key_Numeric
    • [x] go test -run TestTOMLTest_Valid_Key_QuotedDots
    • [x] go test -run TestTOMLTest_Valid_Key_Space
    • [x] go test -run TestTOMLTest_Valid_Key_SpecialChars
    • [x] go test -run TestTOMLTest_Valid_Key_SpecialWord
    • [x] go test -run TestTOMLTest_Valid_NewlineCrlf
    • [x] go test -run TestTOMLTest_Valid_NewlineLf
    • [x] go test -run TestTOMLTest_Valid_SpecExample1Compact
    • [x] go test -run TestTOMLTest_Valid_SpecExample1
    • [x] go test -run TestTOMLTest_Valid_String_DoubleQuoteEscape
    • [x] go test -run TestTOMLTest_Valid_String_Empty
    • [x] go test -run TestTOMLTest_Valid_String_EscapeTricky
    • [x] go test -run TestTOMLTest_Valid_String_EscapedEscape
    • [x] go test -run TestTOMLTest_Valid_String_Escapes
    • [x] go test -run TestTOMLTest_Valid_String_MultilineQuotes
    • [x] go test -run TestTOMLTest_Valid_String_Multiline
    • [x] go test -run TestTOMLTest_Valid_String_Nl
    • [x] go test -run TestTOMLTest_Valid_String_RawMultiline
    • [x] go test -run TestTOMLTest_Valid_String_Raw
    • [x] go test -run TestTOMLTest_Valid_String_Simple
    • [x] go test -run TestTOMLTest_Valid_String_UnicodeEscape
    • [x] go test -run TestTOMLTest_Valid_String_UnicodeLiteral
    • [x] go test -run TestTOMLTest_Valid_String_WithPound
    • [x] go test -run TestTOMLTest_Valid_Table_ArrayImplicit
    • [x] go test -run TestTOMLTest_Valid_Table_ArrayMany
    • [x] go test -run TestTOMLTest_Valid_Table_ArrayNest
    • [x] go test -run TestTOMLTest_Valid_Table_ArrayOne
    • [x] go test -run TestTOMLTest_Valid_Table_ArrayTableArray
    • [x] go test -run TestTOMLTest_Valid_Table_Empty
    • [x] go test -run TestTOMLTest_Valid_Table_Keyword
    • [x] go test -run TestTOMLTest_Valid_Table_Names
    • [x] go test -run TestTOMLTest_Valid_Table_NoEol
    • [x] go test -run TestTOMLTest_Valid_Table_SubEmpty
    • [x] go test -run TestTOMLTest_Valid_Table_Whitespace
    • [x] go test -run TestTOMLTest_Valid_Table_WithLiteralString
    • [x] go test -run TestTOMLTest_Valid_Table_WithPound
    • [x] go test -run TestTOMLTest_Valid_Table_WithSingleQuotes
    • [x] go test -run TestTOMLTest_Valid_Table_WithoutSuper
  • Add continuous fuzzing integration via Fuzzit

    Add continuous fuzzing integration via Fuzzit

    Hi @pelletier This is the PR as discussed in https://github.com/pelletier/go-toml/issues/287

    It adds the following:

    • Runs fuzzing continuously on master
    • Runs regression with the generated corpus from the above step on every PR.

    Cheers, Yevgeny

  • toml.Unmarshal overrides origin values if key is omitted in the file

    toml.Unmarshal overrides origin values if key is omitted in the file

    Describe the bug When unmarshaling to struct that already have some default value toml.Unmarshal overwrites it when key is not present in the file

    To Reproduce Steps to reproduce the behavior. Including TOML files.

    
    package main
    
    import(
    	"github.com/pelletier/go-toml"
    )
    
    type config struct {
    	Val1 string `toml:"val1"`
    	Val2 string `toml:"val2"`
    }
    
    var configFile = []byte(
    	`
    val1 = "test1"
    `)
    
    func main() {
    	cfg := &config {
    		Val2: "test2",
    	}
    
    	err := toml.Unmarshal(configFile, cfg)
    	if err != nil {
    		panic(err.Error())
    	}
    
    	if cfg.Val2 != "test2" {
    		panic("Val2 overwritten")
    	}
    }
    

    Expected behavior Should remain default value if no key is present in the file

    Versions

    • go-toml: b56e1b2
    • go: version 1.11.2
    • operating system: macOS
  • Element Position Support

    Element Position Support

    So, this change may be a tad controversial. If you want, we can hash out a better way to do all this if the changeset doesn't fit with what you have in mind for go-toml.

    The motivation for this change was that there is a real need to be able to trace where a given TOML table, and its associated keys, came from in the source file. With that information, the programmer can inform the user of semantic mistakes made in a given TOML file. As an experiment, I'm using this version of the feature on Grapnel: https://github.com/eanderton/grapnel/blob/master/src/grapnel/rewrite.go#L126 Here, this feature is used to inform the user of where they have made grammatical mistakes in regular expressions and templates in strings, that may be embedded deep within a configuration file.

    The first thing I did was modify the parser to record position information from the token stream. This wound up being a parallel structure (PositionMap) that is stored alongside the TomlTree during parsing. After that, I needed a structure to couple those two together for the library user - this became the TomlDocument.

    A quirk of the position storage scheme is that it was not possible to modify the TomlTree, nor the storage of key/value data, without invalidating the current API. As a result, it's necessary to use a key's parent TomlTree pointer in order to find the location of that key in the document. The TomlDocument also provides methods to query this position information using string paths, in order to parallel the path navigation available on the TomlTree itself.


    TomlDocument provides an optional TOML processing path where position informaiton is stored alongside a TomlTree.

    • Added Position struct
    • Added TomlDocument struct
    • Revised parser to emit position data
    • Revised LoadFile() and Load() to use revised parser
    • Revised token to use new Position struct
    • Added tests for new functionality
    • Bugfixed table array duplicate key handling
    • Applied gofmt to all code
  • add value string representation pub function

    add value string representation pub function

    fix #468

    Issue: add link to pelletier/go-toml issue here

    Explanation of what this pull request does.

    More detailed description of the decisions being made and the reasons why (if the patch is non-trivial).

  • Add compiled binaries to releases

    Add compiled binaries to releases

    Is your feature request related to a problem? Please describe.

    I'd like to be able to use the tomljson binary in a heroku buildpack to parse toml files from a Julia project. At the moment, I need to install Golang and then manually compile tomljson, which adds extra time to my app deploy.

    Describe the solution you'd like

    It would be great if each release on github also had the built binaries (for Darwin and Linux) attached to them, that way I could download the binary as necessary.

    Describe alternatives you've considered

    The alternative is to manually build and compile these, but having them with the release would be a nice way for others to ensure they aren't getting lord-knows-what from my buildpack. In essence, we are trusting you, as the library developer, to build the right thing :)

  • return error

    return error "incorrect date/time separation character:" when add new line after local date

    Describe the bug return error "incorrect date/time separation character:" when add new line after local date

    To Reproduce

    // ok
    "foo = 2021-04-08"  
    
    // error
    `
    foo = 2021-04-08
    bar = 2021-04-08
    `
    

    v1.8.1 is ok, but v1.9.0 will return error

    Expected behavior not return error

    Versions

    • go-toml: v1.9.0
    • go: go1.16.3
    • operating system: Windows

    Additional context no

  • Unmarshal leads to panic

    Unmarshal leads to panic

    Describe the bug my config.toml includes accidently [[devices]] and [[meters]] instead of [[device]] and [[meter]] (note the missing "s"). I expect to get an err, not a kernel panic. Seems that there is something wrong with regex or substrings?

    To Reproduce

    type MeterConfig struct {
    	ID       int `json:"id" toml:"id"`
    	Register int `json:"register" toml:"register"`
    	OldID    int `json:"old_id,omitempty" toml:"-"`
    }
    
    type DeviceConfig struct {
    	Name       string `toml:"name"`
    	SerialPath string `toml:"serial_path"`
    	LinkMode   string `toml:"link_mode"`
    }
    
    type Config struct {
    	Meter  []MeterConfig  `toml:"meter"`
    	Device []DeviceConfig `toml:"device"`
    	Title  string         `toml:"title"`
    }
    
    title = "foo"
    
    [[devices]]
    name = "xyz"
    serial_path = "/dev/ttyUSB0"
    link_mode = "C1"
    
    [[meters]]
    id = 12345678
    register = 12345
    
    
    func readConfig(path string) (Config, error) {
    	wmbusConfig, err := ioutil.ReadFile(path)
    	if err != nil {
    		return Config{}, err
    	}
    
    	config := Config{}
    	err = toml.Unmarshal(wmbusConfig, &config)  <--------------------kernel panic
    	if err != nil {
    		return Config{}, err
    	}
    
    	return config, nil
    }
    
    

    Versions

    • go-toml: v1.8.1
    • go: 1.14
    • operating system: Linux
  • Wrong marshaling map

    Wrong marshaling map

    When marshaling a nested map an invalid toml file is generated

    Reproduce

    var testData map[string]any = map[string]any{
    	"plugins": map[string]any{
    		"io.containerd.grpc.v1.cri": map[string]any{
    			"containerd": map[string]any{
    				"runtimes": map[string]any{
    					"runc": map[string]any{
    						"options": map[string]any{
    							"SystemdCgroup": true,
    						},
    						"runtime_type": "io.containerd.runc.v2",
    					},
    				},
    			},
    		},
    	},
    	"version": 2,
    }
    
    // v2 "github.com/pelletier/go-toml/v2"
    data, _ = v2.Marshal(testData)
    fmt.Printf("%s\n", data)
    

    Actual result

    version = 2
    
    [plugins]
    [plugins.'io.containerd.grpc.v1.cri']
    [plugins.'io.containerd.grpc.v1.cri'.containerd]
    [plugins.'io.containerd.grpc.v1.cri'.containerd.runtimes]
    [plugins.'io.containerd.grpc.v1.cri'.containerd.runtimes.runc]
    runtime_type = 'io.containerd.runc.v2'
    
    [plugins.'io.containerd.grpc.v1.cri'.containerd.runtimes.runc.options]
    SystemdCgroup = true
    

    Expected result

    version = 2
    
    [plugins]
    
      [plugins."io.containerd.grpc.v1.cri"]
    
        [plugins."io.containerd.grpc.v1.cri".containerd]
    
          [plugins."io.containerd.grpc.v1.cri".containerd.runtimes]
    
            [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
              runtime_type = "io.containerd.runc.v2"
    
              [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
                SystemdCgroup = true
    

    Versions

    • go-toml: 58a592bbf8f9fb134915b26ff12fd369bd3ca846
    • go: version go1.19.4 linux/amd64
    • operating system: Linux
  • Cannot decode integers into floats

    Cannot decode integers into floats

    Describe the bug I have a config with entries like

    foo = 5
    

    And I would like to decode them into a float64. This errors with: toml: cannot decode TOML integer into struct field main.conf.Foo of type float64

    To Reproduce

    package main
    
    import (
            "log"
    
            toml "github.com/pelletier/go-toml/v2"
    )
    
    func main() {
            type conf struct {
                    Foo float64 `json:"foo"`
            }
            var c conf
    
            buf := []byte(`foo = 5`)
    
            if err := toml.Unmarshal(buf, &c); err != nil {
                    log.Fatal(err)
            }
            log.Printf("%+v", c)
    }
    

    Expected behavior I think it would be good to be able to deserialize ints into floats. encoding/json works that way for instance.

    Versions

    • go-toml: github.com/pelletier/go-toml/v2 v2.0.6
    • go: go version go1.19.4 linux/amd64
    • operating system: Linux

    Additional context I could write the config values as 5.0 to get around this. However the same config is also used by a Perl parser, which has a different issue when expressing numbers as 5.0. It would be helpful in my case to be able to leave it as "5".

    Thank you!

  • build(deps): bump goreleaser/goreleaser-action from 3 to 4

    build(deps): bump goreleaser/goreleaser-action from 3 to 4

    Bumps goreleaser/goreleaser-action from 3 to 4.

    Release notes

    Sourced from goreleaser/goreleaser-action's releases.

    v4.0.0

    What's Changed

    Full Changelog: https://github.com/goreleaser/goreleaser-action/compare/v3...v4.0.0

    v3.2.0

    What's Changed

    • chore: remove workaround for setOutput by @​crazy-max (#374)
    • chore(deps): bump @​actions/core from 1.9.1 to 1.10.0 (#372)
    • chore(deps): bump yargs from 17.5.1 to 17.6.0 (#373)

    Full Changelog: https://github.com/goreleaser/goreleaser-action/compare/v3.1.0...v3.2.0

    v3.1.0

    What's Changed

    • fix: dist resolution from config file by @​crazy-max (#369)
    • ci: fix workflow by @​crazy-max (#357)
    • docs: bump actions to latest major by @​crazy-max (#356)
    • chore(deps): bump crazy-max/ghaction-import-gpg from 4 to 5 (#360)
    • chore(deps): bump ghaction-import-gpg to v5 (#359)
    • chore(deps): bump @​actions/core from 1.6.0 to 1.8.2 (#358)
    • chore(deps): bump @​actions/core from 1.8.2 to 1.9.1 (#367)

    Full Changelog: https://github.com/goreleaser/goreleaser-action/compare/v3.0.0...v3.1.0

    Commits
    • 8f67e59 chore: regenerate
    • 78df308 chore(deps): bump minimatch from 3.0.4 to 3.1.2 (#383)
    • 66134d9 Merge remote-tracking branch 'origin/master' into flarco/master
    • 3c08cfd chore(deps): bump yargs from 17.6.0 to 17.6.2
    • 5dc579b docs: add example when using workdir along with upload-artifact (#366)
    • 3b7d1ba feat!: remove auto-snapshot on dirty tag (#382)
    • 23e0ed5 fix: do not override GORELEASER_CURRENT_TAG (#370)
    • 1315dab update build
    • b60ea88 improve install
    • 4d25ab4 Update goreleaser.ts
    • See full diff in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • Apply multiline tag to value instead of container for non-arrays

    Apply multiline tag to value instead of container for non-arrays

    Discussed in https://github.com/pelletier/go-toml/discussions/823

    Instead of multiline being a no-op when used on non-string or non-array, it should be pushed down for the value if it is an array. I think this would match people's expectations, as seen in the discussion.

    For a case like this:

    struct {
      Field map[string][][]string `toml:",multiline"`
    }
    

    it should only make the outer array multiline. Maybe at some point we'll need a different API for those who want more granular control to emit toml.

  • Make AST package available for generic data manipulation

    Make AST package available for generic data manipulation

    Hi,

    I'm the author of yq (github.com/mikefarah/yq) which is a popular command line tool for manipulating data files (yml, json, xml, properties). I'd love to add TOML support (https://github.com/mikefarah/yq/issues/1364) - and this libary seems like it'd be a best fit...if the internal AST package was made public.

    That way I could (attempt) to preserve comments, map key order etc.

    Is this something you would consider? Happy to help if I can...

Light weight, extensible configuration management library for Go. Built in support for JSON, TOML, YAML, env, command line, file, S3 etc. Alternative to viper.
Light weight, extensible configuration management library for Go. Built in support for JSON, TOML, YAML, env, command line, file, S3 etc. Alternative to viper.

koanf (pronounced conf; a play on the Japanese Koan) is a library for reading configuration from different sources in different formats in Go applicat

Jan 8, 2023
TOML parser and encoder library for Golang

TOML parser and encoder library for Golang TOML parser and encoder library for Golang. This library is compatible with TOML version v0.4.0. Installati

Oct 11, 2022
TOML parser for Golang with reflection.

THIS PROJECT IS UNMAINTAINED The last commit to this repo before writing this message occurred over two years ago. While it was never my intention to

Jan 6, 2023
Golang Configuration tool that support YAML, JSON, TOML, Shell Environment

Configor Golang Configuration tool that support YAML, JSON, TOML, Shell Environment (Supports Go 1.10+) Usage package main import ( "fmt" "github.c

Dec 29, 2022
Generic templating tool with support of JSON, YAML and TOML data

gotempl Small binary used to generate files from Go Templates and data files. The following formats are supported: JSON YAML TOML Usage usage: gotempl

Jun 15, 2022
Tmpl - A tool to apply variables from cli, env, JSON/TOML/YAML files to templates

tmpl allows to apply variables from JSON/TOML/YAML files, environment variables or CLI arguments to template files using Golang text/template and functions from the Sprig project.

Nov 14, 2022
YAML support for the Go language.

YAML support for the Go language Introduction The yaml package enables Go programs to comfortably encode and decode YAML values. It was developed with

Jan 8, 2023
HCL is the HashiCorp configuration language.

HCL HCL is a toolkit for creating structured configuration languages that are both human- and machine-friendly, for use with command-line tools. Altho

Jan 9, 2023
Tom's Obvious, Minimal Language

TOML Tom's Obvious, Minimal Language. By Tom Preston-Werner, Pradyun Gedam, et al. This repository contains the in-development version of the TOML spe

Jan 2, 2023
Graph-based Declarative Configuration Language
Graph-based Declarative Configuration Language

Virgo Configuration Language Most configuration problems reduce to graphs, e.g. Dockerfiles and Makefiles But there are no graph-based configuration l

Nov 26, 2022
YAML support for the Go language
YAML support for the Go language

YAML support for the Go language

Dec 31, 2022
Library for setting values to structs' fields from env, flags, files or default tag

Configuration is a library for injecting values recursively into structs - a convenient way of setting up a configuration object. Available features:

Dec 7, 2022
Small library to read your configuration from environment variables

envconfig envconfig is a library which allows you to parse your configuration from environment variables and fill an arbitrary struct. See the example

Nov 3, 2022
A minimalist Go configuration library
A minimalist Go configuration library

fig fig is a tiny library for loading an application's config file and its environment into a Go struct. Individual fields can have default values def

Dec 23, 2022
Genv is a library for Go (golang) that makes it easy to read and use environment variables in your projects. It also allows environment variables to be loaded from the .env file.

genv Genv is a library for Go (golang) that makes it easy to read and use environment variables in your projects. It also allows environment variables

Dec 21, 2022
go-up! A simple configuration library with recursive placeholders resolution and no magic.

go-up! A simple configuration library with placeholders resolution and no magic. go-up provides a simple way to configure an application from multiple

Nov 23, 2022
A Go port of Ruby's dotenv library (Loads environment variables from `.env`.)

GoDotEnv A Go (golang) port of the Ruby dotenv project (which loads env vars from a .env file) From the original Library: Storing configuration in the

Jan 5, 2023
go implementation of lightbend's HOCON configuration library https://github.com/lightbend/config

HOCON (Human-Optimized Config Object Notation) Configuration library for working with the Lightbend's HOCON format. HOCON is a human-friendly JSON sup

Dec 3, 2022