github.com/greenboxal/deis@v1.12.1/logspout/types.go (about) 1 package main 2 3 import ( 4 "encoding/json" 5 "io" 6 "io/ioutil" 7 "log" 8 ) 9 10 type AttachEvent struct { 11 Type string 12 ID string 13 Name string 14 } 15 16 type Log struct { 17 ID string `json:"id"` 18 Name string `json:"name"` 19 Type string `json:"type"` 20 Data string `json:"data"` 21 } 22 23 type Route struct { 24 ID string `json:"id"` 25 Source *Source `json:"source,omitempty"` 26 Target Target `json:"target"` 27 closer chan bool 28 } 29 30 type Source struct { 31 ID string `json:"id,omitempty"` 32 Name string `json:"name,omitempty"` 33 Filter string `json:"filter,omitempty"` 34 Types []string `json:"types,omitempty"` 35 } 36 37 func (s *Source) All() bool { 38 return s.ID == "" && s.Name == "" && s.Filter == "" 39 } 40 41 type Target struct { 42 Type string `json:"type"` 43 Addr string `json:"addr"` 44 Protocol string `json:"protocol"` 45 AppendTag string `json:"append_tag,omitempty"` 46 } 47 48 func marshal(obj interface{}) []byte { 49 bytes, err := json.MarshalIndent(obj, "", " ") 50 if err != nil { 51 log.Println("marshal:", err) 52 } 53 return bytes 54 } 55 56 func unmarshal(input io.ReadCloser, obj interface{}) error { 57 body, err := ioutil.ReadAll(input) 58 if err != nil { 59 return err 60 } 61 err = json.Unmarshal(body, obj) 62 if err != nil { 63 return err 64 } 65 return nil 66 }