yamlunmarshaler.go 595 B

123456789101112131415161718192021222324252627
  1. package mapping
  2. import (
  3. "io"
  4. "github.com/wuntsong-org/go-zero-plus/internal/encoding"
  5. )
  6. // UnmarshalYamlBytes unmarshals content into v.
  7. func UnmarshalYamlBytes(content []byte, v any, opts ...UnmarshalOption) error {
  8. b, err := encoding.YamlToJson(content)
  9. if err != nil {
  10. return err
  11. }
  12. return UnmarshalJsonBytes(b, v, opts...)
  13. }
  14. // UnmarshalYamlReader unmarshals content from reader into v.
  15. func UnmarshalYamlReader(reader io.Reader, v any, opts ...UnmarshalOption) error {
  16. b, err := io.ReadAll(reader)
  17. if err != nil {
  18. return err
  19. }
  20. return UnmarshalYamlBytes(b, v, opts...)
  21. }