Skip to content

Commit

Permalink
feat: remove v1 toml parser
Browse files Browse the repository at this point in the history
  • Loading branch information
GreyXor committed Feb 14, 2024
1 parent 12718c3 commit e42d6ac
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 230 deletions.
6 changes: 3 additions & 3 deletions parsers/toml/go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module github.com/knadh/koanf/parsers/toml
module github.com/knadh/koanf/parsers/toml/v2

go 1.18

require (
github.com/pelletier/go-toml v1.9.5
github.com/stretchr/testify v1.8.1
github.com/pelletier/go-toml/v2 v2.1.1
github.com/stretchr/testify v1.8.4
)

require (
Expand Down
8 changes: 4 additions & 4 deletions parsers/toml/go.sum
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI=
github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
17 changes: 9 additions & 8 deletions parsers/toml/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
package toml

import (
"bytes"

"github.com/pelletier/go-toml"
"github.com/pelletier/go-toml/v2"
)

// TOML implements a TOML parser.
Expand All @@ -17,18 +15,21 @@ func Parser() *TOML {

// Unmarshal parses the given TOML bytes.
func (p *TOML) Unmarshal(b []byte) (map[string]interface{}, error) {
r, err := toml.LoadReader(bytes.NewBuffer(b))
if err != nil {
var outMap map[string]interface{}

if err := toml.Unmarshal(b, &outMap); err != nil {
return nil, err
}
return r.ToMap(), err

return outMap, nil
}

// Marshal marshals the given config map to TOML bytes.
func (p *TOML) Marshal(o map[string]interface{}) ([]byte, error) {
out, err := toml.TreeFromMap(o)
out, err := toml.Marshal(&o)
if err != nil {
return nil, err
}
return out.Marshal()

return out, nil
}
16 changes: 8 additions & 8 deletions parsers/toml/toml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestTOML_Unmarshal(t *testing.T) {
{
name: "Empty TOML",
input: []byte(``),
output: map[string]interface{}{},
output: map[string]interface{}(nil),
},
{
name: "Valid TOML",
Expand Down Expand Up @@ -95,8 +95,8 @@ func TestTOML_Marshal(t *testing.T) {
"name": "test",
"number": 2.0,
},
output: []byte(`key = "val"
name = "test"
output: []byte(`key = 'val'
name = 'test'
number = 2.0
`),
},
Expand All @@ -110,15 +110,15 @@ number = 2.0
"object": map[string]interface{}{"a": "b", "c": "d"},
"string": "Hello World",
},
output: []byte(`array = [1,2,3,4,5]
output: []byte(`array = [1, 2, 3, 4, 5]
boolean = true
color = "gold"
color = 'gold'
number = 123
string = "Hello World"
string = 'Hello World'
[object]
a = "b"
c = "d"
a = 'b'
c = 'd'
`),
},
}
Expand Down
14 changes: 0 additions & 14 deletions parsers/toml/v2/go.mod

This file was deleted.

19 changes: 0 additions & 19 deletions parsers/toml/v2/go.sum

This file was deleted.

35 changes: 0 additions & 35 deletions parsers/toml/v2/toml.go

This file was deleted.

139 changes: 0 additions & 139 deletions parsers/toml/v2/toml_test.go

This file was deleted.

0 comments on commit e42d6ac

Please sign in to comment.