✨ Make IntOrString support TOML as well
This commit is contained in:
parent
f4497aef7e
commit
e8401db519
3 changed files with 77 additions and 17 deletions
|
|
@ -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 == ""
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue