first commit
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
andrey1s
2021-04-26 16:07:41 +03:00
commit d6e6001d6b
18 changed files with 348 additions and 0 deletions

24
yaml/encoding.go Normal file
View 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
View 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)
}