diff --git a/actions/printer.go b/actions/printer.go index 43b4ac9..e436743 100644 --- a/actions/printer.go +++ b/actions/printer.go @@ -1,6 +1,7 @@ package actions import ( + "encoding/json" "fmt" "unknown.com/gokill/internal" @@ -17,14 +18,15 @@ func (p Printer) Execute() { } func NewPrint(config internal.ActionConfig, c chan bool) (Action, error) { - opts := config.Options - message, ok := opts["message"] + var result Printer + err := json.Unmarshal(config.Options, &result) - if !ok { + if err != nil { return nil, internal.OptionMissingError{"message"} } - return Printer{fmt.Sprintf("%v", message), c}, nil + result.ActionChan = c + return result, nil } func (p Printer) GetName() string { diff --git a/actions/timeout.go b/actions/timeout.go index cd0b97d..eb84ae9 100644 --- a/actions/timeout.go +++ b/actions/timeout.go @@ -1,6 +1,7 @@ package actions import ( + "encoding/json" "fmt" "time" @@ -19,14 +20,15 @@ func (t TimeOut) Execute() { } func NewTimeOut(config internal.ActionConfig, c chan bool) (Action, error) { - opts := config.Options - duration, ok := opts["duration"] + var result TimeOut + err := json.Unmarshal(config.Options, &result) - if !ok { + if err != nil { return nil, internal.OptionMissingError{"duration"} } - return TimeOut{time.Duration(duration.(float64)) * time.Second, c}, nil + result.ActionChan = c + return result, nil } func (p TimeOut) GetName() string { diff --git a/internal/config.go b/internal/config.go index 19f32fd..1737d31 100644 --- a/internal/config.go +++ b/internal/config.go @@ -1,6 +1,9 @@ package internal -import "fmt" +import ( + "encoding/json" + "fmt" +) type OptionMissingError struct { OptionName string @@ -10,12 +13,10 @@ func (o OptionMissingError) Error() string { return fmt.Sprintf("Error during config parsing: option %s could not be parsed.", o.OptionName) } -type Options map[string]interface{} - type ActionConfig struct { - Type string `json:"type"` - Options Options `json:"options"` - Stage int `json:"stage"` + Type string `json:"type"` + Options json.RawMessage `json:"options"` + Stage int `json:"stage"` } type KillSwitchConfig struct {