1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-01-30 04:31:03 +02:00
kratos/encoding/yaml/yaml.go
2021-06-30 11:55:01 +08:00

29 lines
497 B
Go

package yaml
import (
"github.com/go-kratos/kratos/v2/encoding"
"gopkg.in/yaml.v3"
)
// Name is the name registered for the yaml codec.
const Name = "yaml"
func init() {
encoding.RegisterCodec(codec{})
}
// codec is a Codec implementation with yaml.
type codec struct{}
func (codec) Marshal(v interface{}) ([]byte, error) {
return yaml.Marshal(v)
}
func (codec) Unmarshal(data []byte, v interface{}) error {
return yaml.Unmarshal(data, v)
}
func (codec) Name() string {
return Name
}