home: allow disableing list
This commit is contained in:
parent
35544bd64c
commit
5e9795ad0c
9 changed files with 127 additions and 32 deletions
41
internal/config/validators/bool.go
Normal file
41
internal/config/validators/bool.go
Normal 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
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue