Make IntOrString support TOML as well

This commit is contained in:
Dan Jones 2025-07-18 16:55:54 -05:00
commit e8401db519
3 changed files with 77 additions and 17 deletions

View file

@ -10,17 +10,8 @@ func (ye *YamlTypeError) Error() string {
return ye.Node.Tag + " is not a valid type for this field"
}
type IntOrString struct {
intVal int
strVal string
isInt bool
}
func (is IntOrString) MarshalYAML() (any, error) {
if is.isInt {
return is.intVal, nil
}
return is.strVal, nil
return is.Value(), nil
}
func (is *IntOrString) UnmarshalYAML(value *yaml.Node) error {
@ -36,10 +27,3 @@ func (is *IntOrString) UnmarshalYAML(value *yaml.Node) error {
return &YamlTypeError{Node: value}
}
func (is IntOrString) IsZero() bool {
if is.isInt {
return is.intVal == 0
}
return is.strVal == ""
}