mirror of
https://github.com/bettercap/bettercap
synced 2025-07-11 15:46:59 -07:00
Decimal support for events.stream.output.rotate.when
This commit is contained in:
parent
fc7d8d22b4
commit
251dbb3ef2
4 changed files with 28 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue