-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson-builder.go
57 lines (52 loc) · 1.47 KB
/
json-builder.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
package main
import (
"encoding/json"
"io"
"os"
)
func readJSON(rc io.ReadCloser, data interface{}) error {
defer rc.Close()
return json.NewDecoder(rc).Decode(data)
}
type EnvPair struct {
Name string `json:"name"`
Value string `json:"value"`
}
type Dockerrun struct {
AWSEBDockerrunVersion int `json:"AWSEBDockerrunVersion"`
ContainerDefinitions []*struct {
Command []string `json:"command,omitempty"`
Essential bool `json:"essential"`
Image string `json:"image"`
MemoryReservation int `json:"memoryReservation"`
Name string `json:"name"`
Environment []EnvPair `json:"environment,omitempty"`
MountPoints []struct {
SourceVolume string `json:"sourceVolume"`
ContainerPath string `json:"containerPath"`
ReadOnly bool `json:"readOnly"`
} `json:"mountPoints"`
Links []string `json:"links,omitempty"`
PortMappings []struct {
ContainerPort int `json:"containerPort"`
HostPort int `json:"hostPort"`
} `json:"portMappings,omitempty"`
} `json:"containerDefinitions"`
Family string `json:"family"`
Volumes []struct {
Name string `json:"name"`
Host struct {
SourcePath string `json:"sourcePath"`
} `json:"host"`
} `json:"volumes"`
}
func writeJSON(filename string, data interface{}) error {
f, err := os.Create(filename)
if err != nil {
return err
}
defer f.Close()
enc := json.NewEncoder(f)
enc.SetIndent("", " ")
return enc.Encode(data)
}