2020-07-26 17:09:05 +08:00
|
|
|
package mapping
|
|
|
|
|
|
|
|
import (
|
2022-02-09 16:57:00 +08:00
|
|
|
"io"
|
2022-02-09 17:22:52 +08:00
|
|
|
|
2022-12-08 22:01:36 +08:00
|
|
|
"github.com/zeromicro/go-zero/internal/encoding"
|
2020-07-26 17:09:05 +08:00
|
|
|
)
|
|
|
|
|
2021-02-20 23:18:22 +08:00
|
|
|
// UnmarshalYamlBytes unmarshals content into v.
|
2022-12-08 22:01:36 +08:00
|
|
|
func UnmarshalYamlBytes(content []byte, v interface{}, opts ...UnmarshalOption) error {
|
|
|
|
b, err := encoding.YamlToJson(content)
|
|
|
|
if err != nil {
|
2022-02-09 17:22:52 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-12-08 22:01:36 +08:00
|
|
|
return UnmarshalJsonBytes(b, v, opts...)
|
2022-02-09 17:22:52 +08:00
|
|
|
}
|
|
|
|
|
2022-12-08 22:01:36 +08:00
|
|
|
// UnmarshalYamlReader unmarshals content from reader into v.
|
|
|
|
func UnmarshalYamlReader(reader io.Reader, v interface{}, opts ...UnmarshalOption) error {
|
|
|
|
b, err := io.ReadAll(reader)
|
|
|
|
if err != nil {
|
2022-02-09 17:22:52 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-12-08 22:01:36 +08:00
|
|
|
return UnmarshalYamlBytes(b, v, opts...)
|
2022-02-09 17:22:52 +08:00
|
|
|
}
|