-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdomains.go
More file actions
59 lines (44 loc) · 1.3 KB
/
domains.go
File metadata and controls
59 lines (44 loc) · 1.3 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
package domains
import (
"encoding/json"
"fmt"
"github.com/deis/workflow-cli/controller/api"
"github.com/deis/workflow-cli/controller/client"
)
// List domains registered with an app.
func List(c *client.Client, appID string, results int) ([]api.Domain, int, error) {
u := fmt.Sprintf("/v2/apps/%s/domains/", appID)
body, count, err := c.LimitedRequest(u, results)
if err != nil {
return []api.Domain{}, -1, err
}
var domains []api.Domain
if err = json.Unmarshal([]byte(body), &domains); err != nil {
return []api.Domain{}, -1, err
}
return domains, count, nil
}
// New adds a domain to an app.
func New(c *client.Client, appID string, domain string) (api.Domain, error) {
u := fmt.Sprintf("/v2/apps/%s/domains/", appID)
req := api.DomainCreateRequest{Domain: domain}
body, err := json.Marshal(req)
if err != nil {
return api.Domain{}, err
}
resBody, err := c.BasicRequest("POST", u, body)
if err != nil {
return api.Domain{}, err
}
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("/v2/apps/%s/domains/%s", appID, domain)
_, err := c.BasicRequest("DELETE", u, nil)
return err
}