github.com/econnell/deis@v1.5.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  	AppendTag string `json:"append_tag,omitempty"`
    45  }
    46  
    47  func marshal(obj interface{}) []byte {
    48  	bytes, err := json.MarshalIndent(obj, "", "  ")
    49  	if err != nil {
    50  		log.Println("marshal:", err)
    51  	}
    52  	return bytes
    53  }
    54  
    55  func unmarshal(input io.ReadCloser, obj interface{}) error {
    56  	body, err := ioutil.ReadAll(input)
    57  	if err != nil {
    58  		return err
    59  	}
    60  	err = json.Unmarshal(body, obj)
    61  	if err != nil {
    62  		return err
    63  	}
    64  	return nil
    65  }