/
app.go
121 lines (110 loc) · 2.49 KB
/
app.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package gomarathon
import (
"fmt"
)
/*
* Application requests
*/
// ListApps is listing all apps
func (c *Client) ListApps() (*Response, error) {
return c.ListAppsByCmd("")
}
// ListAppsByCmd list all apps by cmd filter
func (c *Client) ListAppsByCmd(filter string) (*Response, error) {
options := &RequestOptions{
Path: fmt.Sprintf("apps"),
Params: &Parameters{
Cmd: filter,
},
}
r, err := c.request(options)
if err != nil {
return nil, err
}
return r, nil
}
// ListAppVersions list app versions from a define appid
func (c *Client) ListAppVersions(appID string) (*Response, error) {
options := &RequestOptions{
Path: fmt.Sprintf("apps/%s/versions", appID),
}
r, err := c.request(options)
if err != nil {
return nil, err
}
return r, nil
}
// GetApp gets a single app with production version
func (c *Client) GetApp(appID string) (*Response, error) {
options := &RequestOptions{
Path: fmt.Sprintf("apps/%s", appID),
}
r, err := c.request(options)
if err != nil {
return nil, err
}
if r.Code != 200 {
return nil, fmt.Errorf("request rrror")
}
return r, nil
}
// GetAppVersion get a single version from a single app
func (c *Client) GetAppVersion(appID string, version string) (*Response, error) {
options := &RequestOptions{
Path: fmt.Sprintf("apps/%s/versions/%s", appID, version),
}
r, err := c.request(options)
if err != nil {
return nil, err
}
if r.Code != 200 {
return nil, fmt.Errorf("request error")
}
return r, nil
}
// CreateApp Create a new Application
func (c *Client) CreateApp(app *Application) (*Response, error) {
// TODO : VALIDATE DATAS
options := &RequestOptions{
Path: "apps",
Datas: app,
Method: "POST",
}
r, err := c.request(options)
if r != nil {
if r.Code == 201 {
return r, nil
}
}
return nil, err
}
// UpdateApp update the app but thoses changes are made for the next running app and does
// not shut down the production applications
func (c *Client) UpdateApp(appID string, app *Application) (*Response, error) {
options := &RequestOptions{
Path: fmt.Sprintf("apps/%s", appID),
Datas: app,
Method: "PUT",
}
r, err := c.request(options)
if r != nil {
if r.Code == 204 {
return r, nil
}
}
return nil, err
}
// DeleteApp delete this app from the cluster
func (c *Client) DeleteApp(appID string) (*Response, error) {
options := &RequestOptions{
Path: fmt.Sprintf("apps/%s", appID),
Method: "DELETE",
}
r, err := c.request(options)
if r != nil {
if r.Code == 204 {
return r, nil
}
}
return nil, err
}