go-zero/core/mapping/tomlunmarshaler.go

28 lines
610 B
Go
Raw Normal View History

2022-05-13 23:17:43 +08:00
package mapping
import (
"io"
"github.com/zeromicro/go-zero/internal/encoding"
2022-05-13 23:17:43 +08:00
)
// UnmarshalTomlBytes unmarshals TOML bytes into the given v.
func UnmarshalTomlBytes(content []byte, v any, opts ...UnmarshalOption) error {
b, err := encoding.TomlToJson(content)
if err != nil {
2022-05-13 23:17:43 +08:00
return err
}
return UnmarshalJsonBytes(b, v, opts...)
}
// UnmarshalTomlReader unmarshals TOML from the given io.Reader into the given v.
func UnmarshalTomlReader(r io.Reader, v any, opts ...UnmarshalOption) error {
b, err := io.ReadAll(r)
if err != nil {
2022-05-13 23:17:43 +08:00
return err
}
return UnmarshalTomlBytes(b, v, opts...)
2022-05-13 23:17:43 +08:00
}