✨ Add mkflex command
This commit is contained in:
parent
72295c53cf
commit
f4497aef7e
7 changed files with 333 additions and 1 deletions
45
types/yaml.go
Normal file
45
types/yaml.go
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
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"
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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}
|
||||
}
|
||||
|
||||
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