mirror of
https://github.com/Luzifer/go_helpers.git
synced 2024-12-25 21:41:20 +00:00
21 lines
550 B
Go
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
|
|
}
|