Decimal support for events.stream.output.rotate.when

This commit is contained in:
Giuseppe 2018-10-28 22:41:31 +01:00
parent fc7d8d22b4
commit 251dbb3ef2
4 changed files with 28 additions and 6 deletions

View file

@ -18,6 +18,7 @@ const (
STRING ParamType = iota
BOOL = iota
INT = iota
FLOAT = iota
)
type ModuleParam struct {
@ -57,6 +58,10 @@ func NewIntParameter(name string, def_value string, desc string) *ModuleParam {
return NewModuleParameter(name, def_value, INT, "^[\\d]+$", desc)
}
func NewDecimalParameter(name string, def_value string, desc string) *ModuleParam {
return NewModuleParameter(name, def_value, FLOAT, "^[\\d]+(\\.\\d+)?$", desc)
}
func (p ModuleParam) Validate(value string) (error, interface{}) {
if p.Validator != nil {
if !p.Validator.MatchString(value) {
@ -78,6 +83,9 @@ func (p ModuleParam) Validate(value string) (error, interface{}) {
} else if p.Type == INT {
i, err := strconv.Atoi(value)
return err, i
} else if p.Type == FLOAT {
i, err := strconv.ParseFloat(value, 64)
return err, i
}
return fmt.Errorf("Unhandled module parameter type %d.", p.Type), nil