Skip to content

Commit

Permalink
feat!: drop toml v1 support
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
  • Loading branch information
sagikazarmark committed Jan 19, 2023
1 parent e42b933 commit 77fc1c3
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 167 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
go: ['1.16', '1.17', '1.18', '1.19']
tags: ['', 'viper_toml1']
tags: ['']
env:
GOFLAGS: -mod=readonly

Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/hashicorp/hcl v1.0.0
github.com/magiconair/properties v1.8.7
github.com/mitchellh/mapstructure v1.5.0
github.com/pelletier/go-toml v1.9.5
github.com/pelletier/go-toml/v2 v2.0.6
github.com/sagikazarmark/crypt v0.8.0
github.com/spf13/afero v1.9.3
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,6 @@ github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRW
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY=
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
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.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU=
github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down
29 changes: 3 additions & 26 deletions internal/encoding/toml/codec.go
Original file line number Diff line number Diff line change
@@ -1,39 +1,16 @@
//go:build viper_toml1
// +build viper_toml1

package toml

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

// Codec implements the encoding.Encoder and encoding.Decoder interfaces for TOML encoding.
type Codec struct{}

func (Codec) Encode(v map[string]interface{}) ([]byte, error) {
t, err := toml.TreeFromMap(v)
if err != nil {
return nil, err
}

s, err := t.ToTomlString()
if err != nil {
return nil, err
}

return []byte(s), nil
return toml.Marshal(v)
}

func (Codec) Decode(b []byte, v map[string]interface{}) error {
tree, err := toml.LoadBytes(b)
if err != nil {
return err
}

tmap := tree.ToMap()
for key, value := range tmap {
v[key] = value
}

return nil
return toml.Unmarshal(b, &v)
}
19 changes: 0 additions & 19 deletions internal/encoding/toml/codec2.go

This file was deleted.

108 changes: 0 additions & 108 deletions internal/encoding/toml/codec2_test.go

This file was deleted.

16 changes: 6 additions & 10 deletions internal/encoding/toml/codec_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build viper_toml1
// +build viper_toml1

package toml

import (
Expand Down Expand Up @@ -29,17 +26,16 @@ list = [
`

// encoded form of the data
const encoded = `key = "value"
list = ["item1", "item2", "item3"]
const encoded = `key = 'value'
list = ['item1', 'item2', 'item3']
[map]
key = "value"
key = 'value'
[nested_map]
[nested_map.map]
key = "value"
list = ["item1", "item2", "item3"]
[nested_map.map]
key = 'value'
list = ['item1', 'item2', 'item3']
`

// Viper's internal representation
Expand Down

0 comments on commit 77fc1c3

Please sign in to comment.