-
Notifications
You must be signed in to change notification settings - Fork 0
/
shared.go
59 lines (52 loc) · 1.22 KB
/
shared.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 util
import (
"bytes"
"encoding/gob"
"io/ioutil"
)
type PrototypeRequest struct {
Cluster string `json:"cluster"`
Service string `json:"service"`
ID string `json:"id"`
Tags []string `json:"tags"`
EnvoyInfo *EnvoyInfo `json:"envoy_info"`
}
type EnvoyInfo struct {
Version string `json:"version"`
State string `json:"state"`
Uptime string `json:"uptime"`
Timestamp int64 `json:"timestamp"`
}
type HTTPpayload struct {
Cluster string `json:"cluster"`
Service string `json:"service"`
Type string `json:"type"`
Config string `json:"config"`
}
// WriteToDisk writes some data to disk
func WriteToDisk(fileName string, data []byte) error {
err := ioutil.WriteFile(fileName, data, 0644)
if err != nil {
return err
}
return nil
}
func (m PrototypeRequest) EncodeToBytes() ([]byte, error) {
var buffer bytes.Buffer
enc := gob.NewEncoder(&buffer)
err := enc.Encode(m)
if err != nil {
return nil, err
}
return buffer.Bytes(), nil
}
func DecodeFromBytes(q []byte) (PrototypeRequest, error) {
var rm PrototypeRequest
buffer := bytes.NewBuffer(q)
dec := gob.NewDecoder(buffer)
err := dec.Decode(&rm)
if err != nil {
return PrototypeRequest{}, err
}
return rm, nil
}