home: allow disableing list

This commit is contained in:
Tom 2023-04-27 10:49:30 +02:00
parent 35544bd64c
commit 5e9795ad0c
9 changed files with 127 additions and 32 deletions

View file

@ -0,0 +1,41 @@
package validators
import (
"strconv"
"gopkg.in/yaml.v3"
)
// NullableBool represents a bool that can be null
type NullableBool struct {
Null, Value bool
}
func (nb *NullableBool) UnmarshalYAML(value *yaml.Node) error {
nb.Null = false
if err := value.Decode(&nb.Value); err != nil {
nb.Null = true
nb.Value = false
}
return nil
}
func (nb *NullableBool) MarshalYAML() (interface{}, error) {
if nb.Null {
return nil, nil
}
return nb.Value, nil
}
func ValidateBool(value *NullableBool, dflt string) (err error) {
if value.Null {
res, err := strconv.ParseBool(dflt)
if err != nil {
return err
}
value.Null = false
value.Value = res
}
return err
}

View file

@ -10,6 +10,8 @@ func New() validator.Collection {
validator.Add(coll, "nonempty", ValidateNonempty)
validator.Add(coll, "bool", ValidateBool)
validator.Add(coll, "directory", ValidateDirectory)
validator.Add(coll, "file", ValidateFile)