29 lines
541 B
Go
29 lines
541 B
Go
package types
|
|
|
|
import "gopkg.in/yaml.v3"
|
|
|
|
type YamlTypeError struct {
|
|
Node *yaml.Node
|
|
}
|
|
|
|
func (ye *YamlTypeError) Error() string {
|
|
return ye.Node.Tag + " is not a valid type for this field"
|
|
}
|
|
|
|
func (is IntOrString) MarshalYAML() (any, error) {
|
|
return is.Value(), nil
|
|
}
|
|
|
|
func (is *IntOrString) UnmarshalYAML(value *yaml.Node) error {
|
|
if value.Tag == `!!int` {
|
|
is.isInt = true
|
|
return value.Decode(&is.intVal)
|
|
}
|
|
|
|
if value.Tag == `!!str` {
|
|
is.isInt = false
|
|
return value.Decode(&is.strVal)
|
|
}
|
|
|
|
return &YamlTypeError{Node: value}
|
|
}
|