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