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

22 lines
435 B
Go
Raw Normal View History

2020-05-09 12:23:37 +02:00
package yaml
2023-08-18 11:27:47 +08:00
import (
"github.com/spf13/viper/internal/encoding/codec"
"gopkg.in/yaml.v3"
)
2020-05-09 12:23:37 +02:00
2023-08-18 11:27:47 +08:00
// Codec implements the encoding.Codec interface for YAML encoding.
2020-05-09 12:23:37 +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) {
2020-05-09 12:23:37 +02:00
return yaml.Marshal(v)
}
2023-08-18 11:27:47 +08:00
func (*Codec) Decode(b []byte, v map[string]interface{}) error {
return yaml.Unmarshal(b, &v)
2020-05-09 12:23:37 +02:00
}