diff --git a/internal/config.go b/internal/config.go index eb238a7..19f32fd 100644 --- a/internal/config.go +++ b/internal/config.go @@ -19,10 +19,10 @@ type ActionConfig struct { } type KillSwitchConfig struct { - Name string `json:"name"` - Type string `json:"type"` - Options Options `json:"options"` - Actions []ActionConfig `json:"actions"` + Name string `json:"name"` + Type string `json:"type"` + Options json.RawMessage `json:"options"` + Actions []ActionConfig `json:"actions"` } type ConfigOption struct { diff --git a/triggers/timeout.go b/triggers/timeout.go index a20146e..9b02a33 100644 --- a/triggers/timeout.go +++ b/triggers/timeout.go @@ -1,6 +1,7 @@ package triggers import ( + "encoding/json" "fmt" "time" @@ -20,14 +21,12 @@ func (t TimeOut) Listen() { t.action.Execute() } -// func NewTimeOut(d time.Duration, action actions.Action) TimeOut { func NewTimeOut(config internal.KillSwitchConfig) (TimeOut, error) { - opts := config.Options + result := TimeOut{d: 0 * time.Second} + err := json.Unmarshal(config.Options, &result) - duration, ok := opts["duration"] - - if !ok { - return TimeOut{}, internal.OptionMissingError{"duration"} + if err != nil { + return TimeOut{}, err } action, err := actions.NewAction(config.Actions) @@ -36,7 +35,8 @@ func NewTimeOut(config internal.KillSwitchConfig) (TimeOut, error) { return TimeOut{}, err } - return TimeOut{time.Duration(duration.(float64)) * time.Second, action}, nil + result.action = action + return result, nil } func (p TimeOut) GetName() string {