-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
66 lines (57 loc) · 1.19 KB
/
types.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
60
61
62
63
64
65
66
package main
import (
"encoding/json"
"io"
"io/ioutil"
"log"
)
type AttachEvent struct {
Type string
ID string
Name string
}
type Log struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Data string `json:"data"`
}
type Route struct {
ID string `json:"id"`
Source *Source `json:"source,omitempty"`
Target Target `json:"target"`
closer chan bool
}
type Source struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Filter string `json:"filter,omitempty"`
Types []string `json:"types,omitempty"`
}
func (s *Source) All() bool {
return s.ID == "" && s.Name == "" && s.Filter == ""
}
type Target struct {
Type string `json:"type"`
Addr string `json:"addr"`
Protocol string `json:"protocol"`
AppendTag string `json:"append_tag,omitempty"`
}
func marshal(obj interface{}) []byte {
bytes, err := json.MarshalIndent(obj, "", " ")
if err != nil {
log.Println("marshal:", err)
}
return bytes
}
func unmarshal(input io.ReadCloser, obj interface{}) error {
body, err := ioutil.ReadAll(input)
if err != nil {
return err
}
err = json.Unmarshal(body, obj)
if err != nil {
return err
}
return nil
}