spf13--viper/internal/encoding/toml/codec.go

22 lines
450 B
Go
Raw Normal View History

package toml
import (
"github.com/pelletier/go-toml/v2"
2023-08-18 11:27:47 +08:00
"github.com/spf13/viper/internal/encoding/codec"
)
2023-08-18 11:27:47 +08:00
// Codec implements the encoding.Codec interface for TOML encoding.
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) {
return toml.Marshal(v)
}
2023-08-18 11:27:47 +08:00
func (*Codec) Decode(b []byte, v map[string]interface{}) error {
return toml.Unmarshal(b, &v)
}