forked from cloud66-oss/cloud66
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service-yaml.go
81 lines (65 loc) · 1.81 KB
/
service-yaml.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package cloud66
import (
"strconv"
"time"
)
type ServiceYaml struct {
Uid string `json:"uid"`
Body string `json:"body"`
Comments string `json:"comments"`
CreatedAt time.Time `json:"created_at_iso"`
UpdatedAt time.Time `json:"updated_at_iso"`
}
func (c *Client) ServiceYamlList(stackUid string, include_body bool) ([]ServiceYaml, error) {
query_strings := make(map[string]string)
query_strings["page"] = "1"
query_strings["include_body"] = strconv.FormatBool(include_body)
var p Pagination
var result []ServiceYaml
var serviceYamlRes []ServiceYaml
for {
req, err := c.NewRequest("GET", "/stacks/"+stackUid+"/service_yaml.json", nil, query_strings)
if err != nil {
return nil, err
}
serviceYamlRes = nil
err = c.DoReq(req, &serviceYamlRes, &p)
if err != nil {
return nil, err
}
result = append(result, serviceYamlRes...)
if p.Current < p.Next {
query_strings["page"] = strconv.Itoa(p.Next)
} else {
break
}
}
return result, nil
}
func (c *Client) ServiceYamlInfo(stackUid string, id string) (*ServiceYaml, error) {
var serviceYamlRes ServiceYaml
req, err := c.NewRequest("GET", "/stacks/"+stackUid+"/service_yaml/"+id+".json", nil, nil)
if err != nil {
return nil, err
}
err = c.DoReq(req, &serviceYamlRes, nil)
if err != nil {
return nil, err
}
return &serviceYamlRes, nil
}
func (c *Client) CreateServiceYaml(stackUid, serviceYaml, comments string) (*ServiceYaml, error) {
params := struct {
ServiceYaml string `json:"service_yaml"`
Comments string `json:"comments"`
}{
ServiceYaml: serviceYaml,
Comments: comments,
}
req, err := c.NewRequest("POST", "/stacks/"+stackUid+"/service_yaml", params, nil)
if err != nil {
return nil, err
}
var serviceYamlRes *ServiceYaml
return serviceYamlRes, c.DoReq(req, &serviceYamlRes, nil)
}