-
Notifications
You must be signed in to change notification settings - Fork 3
/
triggers.go
59 lines (52 loc) · 1.14 KB
/
triggers.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
53
54
55
56
57
58
59
package p4
import (
"bytes"
"text/template"
)
type Triggers struct {
Lines []string
}
func (t *Triggers) String() string {
var (
contentBuf = bytes.NewBuffer(nil)
)
if _, err := _triggersTemplate.Parse(_triggerTemplateTxt); err != nil {
return ""
}
if err := _triggersTemplate.Execute(contentBuf, t); err != nil {
return ""
}
return contentBuf.String()
}
var (
_triggersTemplate = template.New("Trigger config template")
)
var _triggerTemplateTxt = `Triggers:
{{- range .Lines }}
{{.}}
{{- end }}`
func (conn *Conn) WriteTriggers(lines []string) (out []byte, err error) {
t := &Triggers{Lines: lines}
content := []byte(t.String())
return conn.Input([]string{"triggers", "-i"}, content)
}
func (conn *Conn) Triggers() (lines []string, err error) {
var (
result []Result
triggers *Triggers
)
if result, err = conn.RunMarshaled("triggers", []string{"-o"}); err != nil {
return
}
if len(result) == 0 {
return
}
if triggers, _ = result[0].(*Triggers); triggers == nil {
return
}
lines = triggers.Lines
return
}
func (conn *Conn) TriggersDump() (out []byte, err error) {
return conn.Output([]string{"triggers", "-o"})
}