-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdomains.go
More file actions
77 lines (57 loc) · 1.52 KB
/
domains.go
File metadata and controls
77 lines (57 loc) · 1.52 KB
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
package domains
import (
"encoding/json"
"errors"
"fmt"
"github.com/deis/deis/client-go/controller/api"
"github.com/deis/deis/client-go/controller/client"
)
// List domains registered with an app.
func List(c *client.Client, appID string) ([]api.Domain, error) {
u := fmt.Sprintf("/v1/apps/%s/domains/", appID)
body, status, err := c.BasicRequest("GET", u, nil)
if err != nil {
return []api.Domain{}, err
}
if status != 200 {
return []api.Domain{}, errors.New(body)
}
domains := api.Domains{}
if err = json.Unmarshal([]byte(body), &domains); err != nil {
return []api.Domain{}, err
}
return domains.Domains, nil
}
// New adds a domain to an app.
func New(c *client.Client, appID string, domain string) (api.Domain, error) {
u := fmt.Sprintf("/v1/apps/%s/domains/", appID)
req := api.DomainCreateRequest{Domain: domain}
body, err := json.Marshal(req)
if err != nil {
return api.Domain{}, err
}
resBody, status, err := c.BasicRequest("POST", u, body)
if err != nil {
return api.Domain{}, err
}
if status != 201 {
return api.Domain{}, errors.New(resBody)
}
res := api.Domain{}
if err = json.Unmarshal([]byte(resBody), &res); err != nil {
return api.Domain{}, err
}
return res, nil
}
// Delete removes a domain from an app.
func Delete(c *client.Client, appID string, domain string) error {
u := fmt.Sprintf("/v1/apps/%s/domains/%s", appID, domain)
body, status, err := c.BasicRequest("DELETE", u, nil)
if err != nil {
return err
}
if status != 204 {
return errors.New(body)
}
return nil
}