2020-09-23 16:51:49 +02:00
|
|
|
package toml
|
|
|
|
|
|
|
|
import (
|
2023-01-19 15:15:44 +01:00
|
|
|
"github.com/pelletier/go-toml/v2"
|
2023-08-18 11:27:47 +08:00
|
|
|
"github.com/spf13/viper/internal/encoding/codec"
|
2020-09-23 16:51:49 +02:00
|
|
|
)
|
|
|
|
|
2023-08-18 11:27:47 +08:00
|
|
|
// Codec implements the encoding.Codec interface for TOML encoding.
|
2020-09-23 16:51:49 +02:00
|
|
|
type Codec struct{}
|
|
|
|
|
2023-08-18 11:27:47 +08:00
|
|
|
func New(_ ...interface{}) codec.Codec {
|
|
|
|
return &Codec{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*Codec) Encode(v map[string]interface{}) ([]byte, error) {
|
2023-01-19 15:15:44 +01:00
|
|
|
return toml.Marshal(v)
|
2020-09-23 16:51:49 +02:00
|
|
|
}
|
|
|
|
|
2023-08-18 11:27:47 +08:00
|
|
|
func (*Codec) Decode(b []byte, v map[string]interface{}) error {
|
2023-01-19 15:15:44 +01:00
|
|
|
return toml.Unmarshal(b, &v)
|
2020-09-23 16:51:49 +02:00
|
|
|
}
|