Go library for the TOML file format

Overview

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 available 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.

    opened by rwxrob 23
  • 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!

    opened by pelletier 20
  • 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.

    bug hacktoberfest-accepted 
    opened by jidicula 19
  • 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
    bug good first issue v2 
    opened by pelletier 17
  • 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

    opened by yevgenypats 15
  • 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
    bug v2-fixed 
    opened by troian 15
  • 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
    opened by eanderton 14
  • 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).

    opened by vincentserpoul 13
  • 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 :)

    build 
    opened by josegonzalez 12
  • 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

    bug v2-fixed 
    opened by For-ACGN 10
  • 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
    opened by chrisquin 9
  • 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!

    opened by horgh 0
  • 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)
    dependencies github_actions 
    opened by dependabot[bot] 0
  • 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.

    feature 
    opened by pelletier 0
  • 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...

    feature 
    opened by mikefarah 8
  • Fix reflect.*Header in TinyGo.

    Fix reflect.*Header in TinyGo.

    TinyGo uses uintptr for Len and Cap in reflect.*Header, unlike gc which uses int. This commit chooses the correct type using -tags.

    For unrelated reasons, compiling with TinyGo does not yet work. But this eliminates one error.

    bug 
    opened by eNV25 1
Releases(v2.0.6)
A command line tool for mainly exporting logbook records from Google Spreadsheet to PDF file in EASA format

Logbook CLI This is a command line tool for mainly exporting logbook records from Google Spreadsheet to PDF file in EASA format. It also supports rend

Vladimir Simakhin 0 Feb 6, 2022
osu! database file format flexible reader

Example usage package main import ( "fmt" "github.com/l3lackShark/reader" types "github.com/l3lackShark/reader/types" ) type agent struct { Osu

null 1 Nov 24, 2021
go-fastdfs 是一个简单的分布式文件系统(私有云存储),具有无中心、高性能,高可靠,免维护等优点,支持断点续传,分块上传,小文件合并,自动同步,自动修复。Go-fastdfs is a simple distributed file system (private cloud storage), with no center, high performance, high reliability, maintenance free and other advantages, support breakpoint continuation, block upload, small file merge, automatic synchronization, automatic repair.(similar fastdfs).

中文 English 愿景:为用户提供最简单、可靠、高效的分布式文件系统。 go-fastdfs是一个基于http协议的分布式文件系统,它基于大道至简的设计理念,一切从简设计,使得它的运维及扩展变得更加简单,它具有高性能、高可靠、无中心、免维护等优点。 大家担心的是这么简单的文件系统,靠不靠谱,可不

小张 3.3k Jan 8, 2023
Format /etc/fstab files.

Format /etc/fstab files. Features and limitations Can format /etc/fstab files. Will use 2 spaces between all fields, if they are of equal length. The

Alexander F. Rødseth 57 Dec 3, 2022
Go file operations library chasing GNU APIs.

flop flop aims to make copying files easier in Go, and is modeled after GNU cp. Most administrators and engineers interact with GNU utilities every da

The Home Depot 33 Nov 10, 2022
File system event notification library on steroids.

notify Filesystem event notification library on steroids. (under active development) Documentation godoc.org/github.com/rjeczalik/notify Installation

Rafal Jeczalik 788 Dec 31, 2022
goelftools is library written in Go for parsing ELF file.

goelftools goelftools is library written in Go for parsing ELF file. This library is inspired by pyelftools and rbelftools. Motivation The motivation

null 27 Dec 5, 2022
Abstract File Storage

afs - abstract file storage Please refer to CHANGELOG.md if you encounter breaking changes. Motivation Introduction Usage Matchers Content modifiers S

Viant, Inc 221 Dec 30, 2022
a tool for handling file uploads simple

baraka a tool for handling file uploads for http servers makes it easier to make operations with files from the http request. Contents Install Simple

Enes Furkan Olcay 46 Nov 30, 2022
Bigfile -- a file transfer system that supports http, rpc and ftp protocol https://bigfile.site

Bigfile ———— a file transfer system that supports http, rpc and ftp protocol 简体中文 ∙ English Bigfile is a file transfer system, supports http, ftp and

null 238 Dec 31, 2022
Read csv file from go using tags

go-csv-tag Read csv file from Go using tags The project is in maintenance mode. It is kept compatible with changes in the Go ecosystem but no new feat

Louis 101 Nov 16, 2022
Pluggable, extensible virtual file system for Go

vfs Package vfs provides a pluggable, extensible, and opinionated set of file system functionality for Go across a number of file system types such as

C2FO 212 Jan 3, 2023
An epoll(7)-based file-descriptor multiplexer.

poller Package poller is a file-descriptor multiplexer. Download: go get github.com/npat-efault/poller Package poller is a file-descriptor multiplexer

Nick Patavalis 107 Sep 25, 2022
QueryCSV enables you to load CSV files and manipulate them using SQL queries then after you finish you can export the new values to a CSV file

QueryCSV enable you to load CSV files and manipulate them using SQL queries then after you finish you can export the new values to CSV file

Mohamed Shapan 100 Dec 22, 2021
Goful is a CUI file manager written in Go.

Goful Goful is a CUI file manager written in Go. Works on cross-platform such as gnome-terminal and cmd.exe. Displays multiple windows and workspaces.

anmitsu 300 Dec 28, 2022
Read a tar file contents using go1.16 io/fs abstraction

go-tarfs Read a tar file contents using go1.16 io/fs abstraction Usage ⚠️ go-tarfs needs go>=1.16 Install: go get github.com/nlepage/go-tarfs Use: pac

Nicolas Lepage 20 Dec 1, 2022
Open Source Continuous File Synchronization

Goals Syncthing is a continuous file synchronization program. It synchronizes files between two or more computers. We strive to fulfill the goals belo

The Syncthing Project 48.6k Jan 9, 2023
Cross-platform file system notifications for Go.

File system notifications for Go fsnotify utilizes golang.org/x/sys rather than syscall from the standard library. Ensure you have the latest version

fsnotify 7.7k Jan 1, 2023
The best HTTP Static File Server, write with golang+vue

gohttpserver Goal: Make the best HTTP File Server. Features: Human-friendly UI, file uploading support, direct QR-code generation for Apple & Android

Sound Sun 1.9k Dec 30, 2022