1
0
Fork 0
mirror of https://github.com/Luzifer/go_helpers.git synced 2024-12-26 14:01:20 +00:00
go_helpers/fieldcollection/marshalYAML.go

22 lines
550 B
Go
Raw Normal View History

package fieldcollection
import "github.com/pkg/errors"
// Implement YAML marshalling to plain underlying map[string]any
// MarshalYAML implements yaml.Marshaller interface
func (f *FieldCollection) MarshalYAML() (any, error) {
return f.Data(), nil
}
// UnmarshalYAML implements yaml.Unmarshaller interface
func (f *FieldCollection) UnmarshalYAML(unmarshal func(any) error) error {
data := make(map[string]any)
if err := unmarshal(&data); err != nil {
return errors.Wrap(err, "unmarshalling from YAML")
}
f.SetFromData(data)
return nil
}