github.com/DoNewsCode/core@v0.12.3/codec/yaml/yaml.go (about) 1 // Package yaml provides the yaml codec. 2 // 3 // The code and tests in this package is derived from 4 // https://github.com/go-kratos/kratos under MIT license 5 // https://github.com/go-kratos/kratos/blob/main/LICENSE 6 package yaml 7 8 import ( 9 "gopkg.in/yaml.v3" 10 ) 11 12 // Codec is a Codec implementation with yaml. 13 type Codec struct{} 14 15 // Marshal serialize the interface{} to []byte 16 func (Codec) Marshal(v interface{}) ([]byte, error) { 17 return yaml.Marshal(v) 18 } 19 20 // Unmarshal deserialize the []byte to interface{} 21 func (Codec) Unmarshal(data []byte, v interface{}) error { 22 return yaml.Unmarshal(data, v) 23 }