This commit is contained in:
24
yaml/encoding.go
Normal file
24
yaml/encoding.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package yaml
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"gitoa.ru/go-4devs/encoding"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
var _ encoding.Decode = Decode
|
||||
var _ encoding.Encode = Encode
|
||||
|
||||
// Decode from reader to value.
|
||||
func Decode(r io.Reader, v interface{}) error {
|
||||
return yaml.NewDecoder(r).Decode(v)
|
||||
}
|
||||
|
||||
// Encode from value to writer.
|
||||
func Encode(w io.Writer, v interface{}) error {
|
||||
enc := yaml.NewEncoder(w)
|
||||
defer enc.Close()
|
||||
|
||||
return enc.Encode(v)
|
||||
}
|
||||
19
yaml/encoding_test.go
Normal file
19
yaml/encoding_test.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package yaml_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gitoa.ru/go-4devs/encoding/test"
|
||||
"gitoa.ru/go-4devs/encoding/yaml"
|
||||
)
|
||||
|
||||
const data = `
|
||||
string: "string data"
|
||||
time: 2020-05-24T09:15:00Z
|
||||
struct:
|
||||
id: 42
|
||||
`
|
||||
|
||||
func TestDecode(t *testing.T) {
|
||||
test.RunDecode(t, yaml.Decode, data)
|
||||
}
|
||||
Reference in New Issue
Block a user