forked from waffle-iron/core0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.go
52 lines (42 loc) · 1.22 KB
/
command.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package core
import (
"encoding/json"
"fmt"
)
type Route string
//Cmd is an executable command
type Command struct {
ID string `json:"id"`
Command string `json:"command"`
Arguments *json.RawMessage `json:"arguments"`
Queue string `json:"queue"`
StatsInterval int `json:"stats_interval,omitempty"`
MaxTime int `json:"max_time,omitempty"`
MaxRestart int `json:"max_restart,omitempty"`
RecurringPeriod int `json:"recurring_period,omitempty"`
LogLevels []int `json:"log_levels,omitempty"`
Tags string `json:"tags"`
Route Route `json:"-"`
}
type M map[string]interface{}
func MustArguments(args interface{}) *json.RawMessage {
bytes, err := json.Marshal(args)
if err != nil {
panic(err)
}
raw := json.RawMessage(bytes)
return &raw
}
//String represents cmd as a string
func (cmd *Command) String() string {
return fmt.Sprintf("(%s# %s)", cmd.ID, cmd.Command)
}
//LoadCmd loads cmd from json string.
func LoadCmd(str []byte) (*Command, error) {
var cmd Command
err := json.Unmarshal(str, &cmd)
if err != nil {
return nil, err
}
return &cmd, err
}