-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
- Loading branch information
1 parent
e42b933
commit 77fc1c3
Showing
7 changed files
with
10 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters