1
0
Fork 0
mirror of https://github.com/Luzifer/go_helpers.git synced 2024-12-25 21:41:20 +00:00
go_helpers/fieldcollection/marshalYAML.go
Knut Ahlers 6efbc2dd11
Add validation to fieldcollection
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2024-04-03 19:03:45 +02:00

21 lines
550 B
Go

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
}