summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/spf13/viper/internal/encoding/toml
diff options
context:
space:
mode:
authorWim <wim@42.be>2022-04-25 23:50:10 +0200
committerGitHub <noreply@github.com>2022-04-25 23:50:10 +0200
commit67adad3e08fe17d5f7e87468ea47aa76e1662255 (patch)
tree91314fac90d39254e66ae794decfcd21c10a7b20 /vendor/github.com/spf13/viper/internal/encoding/toml
parent2fca3c756373577eab4e0120ccce62eecc1f5ad8 (diff)
downloadmatterbridge-msglm-67adad3e08fe17d5f7e87468ea47aa76e1662255.tar.gz
matterbridge-msglm-67adad3e08fe17d5f7e87468ea47aa76e1662255.tar.bz2
matterbridge-msglm-67adad3e08fe17d5f7e87468ea47aa76e1662255.zip
Update dependencies (#1813)
Diffstat (limited to 'vendor/github.com/spf13/viper/internal/encoding/toml')
-rw-r--r--vendor/github.com/spf13/viper/internal/encoding/toml/codec.go40
-rw-r--r--vendor/github.com/spf13/viper/internal/encoding/toml/codec2.go19
2 files changed, 36 insertions, 23 deletions
diff --git a/vendor/github.com/spf13/viper/internal/encoding/toml/codec.go b/vendor/github.com/spf13/viper/internal/encoding/toml/codec.go
index c043802b..ff1112ca 100644
--- a/vendor/github.com/spf13/viper/internal/encoding/toml/codec.go
+++ b/vendor/github.com/spf13/viper/internal/encoding/toml/codec.go
@@ -1,3 +1,6 @@
+//go:build !viper_toml2
+// +build !viper_toml2
+
package toml
import (
@@ -7,39 +10,30 @@ import (
// Codec implements the encoding.Encoder and encoding.Decoder interfaces for TOML encoding.
type Codec struct{}
-func (Codec) Encode(v interface{}) ([]byte, error) {
- if m, ok := v.(map[string]interface{}); ok {
- t, err := toml.TreeFromMap(m)
- if err != nil {
- return nil, err
- }
-
- s, err := t.ToTomlString()
- if err != nil {
- return nil, err
- }
+func (Codec) Encode(v map[string]interface{}) ([]byte, error) {
+ t, err := toml.TreeFromMap(v)
+ if err != nil {
+ return nil, err
+ }
- return []byte(s), nil
+ s, err := t.ToTomlString()
+ if err != nil {
+ return nil, err
}
- return toml.Marshal(v)
+ return []byte(s), nil
}
-func (Codec) Decode(b []byte, v interface{}) error {
+func (Codec) Decode(b []byte, v map[string]interface{}) error {
tree, err := toml.LoadBytes(b)
if err != nil {
return err
}
- if m, ok := v.(*map[string]interface{}); ok {
- vmap := *m
- tmap := tree.ToMap()
- for k, v := range tmap {
- vmap[k] = v
- }
-
- return nil
+ tmap := tree.ToMap()
+ for key, value := range tmap {
+ v[key] = value
}
- return tree.Unmarshal(v)
+ return nil
}
diff --git a/vendor/github.com/spf13/viper/internal/encoding/toml/codec2.go b/vendor/github.com/spf13/viper/internal/encoding/toml/codec2.go
new file mode 100644
index 00000000..566b7062
--- /dev/null
+++ b/vendor/github.com/spf13/viper/internal/encoding/toml/codec2.go
@@ -0,0 +1,19 @@
+//go:build viper_toml2
+// +build viper_toml2
+
+package toml
+
+import (
+ "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) {
+ return toml.Marshal(v)
+}
+
+func (Codec) Decode(b []byte, v map[string]interface{}) error {
+ return toml.Unmarshal(b, &v)
+}