-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
73 lines (58 loc) · 1.4 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
package lolo
import (
"net/url"
"strconv"
)
type Node struct {
Id string `json:"id"`
}
type Edge struct {
Id string `json:"id"`
}
type App struct {
Id string `json:"id,omitempty"`
Name string `json:"name"`
Description string `json:"description"`
//Nodes []Node `json:"nodes,omitempty"`
//Edges []Edge `json:"edges,omitempty"`
}
type AppList struct {
Apps []App `json:"apps"`
}
func (client *Client) CreateApp(app *App) error {
if err := client.sendRequest("POST", "/apps", *app, app); err != nil {
return err
}
return nil
}
func (client *Client) UpdateApp(app *App) error {
id := (*app).Id
if err := client.sendRequest("PATCH", "/apps/"+id, *app, app); err != nil {
return err
}
return nil
}
func (client *Client) GetApps(limit int) (*AppList, error) {
var appList AppList
base, _ := url.Parse("/apps")
params := url.Values{}
params.Add("limit", strconv.Itoa(limit))
base.RawQuery = params.Encode()
if err := client.sendRequest("GET", base.String(), nil, &appList); err != nil {
return nil, err
}
return &appList, nil
}
func (client *Client) GetApp(id string) (*App, error) {
var app App
if err := client.sendRequest("GET", "/apps/"+id, nil, &app); err != nil {
return nil, err
}
return &app, nil
}
func (client *Client) DeleteApp(id string) error {
if err := client.sendRequest("DELETE", "/apps/"+id, nil, nil); err != nil {
return err
}
return nil
}