-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdomain.go
More file actions
42 lines (36 loc) Β· 864 Bytes
/
domain.go
File metadata and controls
42 lines (36 loc) Β· 864 Bytes
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
package cf
import (
"encoding/json"
"fmt"
"net/http"
)
type (
domainMetadata struct {
Guid string `json:"guid"`
}
domainEntity struct {
Name string `json:"name"`
Spaces []Space `json:"spaces"`
}
)
type Domain struct {
domainMetadata `json:"metadata"`
domainEntity `json:"entity"`
}
func (d Domain) String() string { return fmt.Sprint(d.Name) }
// GetDomains returns a slice of registered domains for given space
func (target *Target) DomainsGet() (domains []Domain, err error) {
url := fmt.Sprintf("%s/v2/domains?inline-relations-depth=2", target.TargetUrl)
req, _ := http.NewRequest("GET", url, nil)
resp, err := target.sendRequest(req)
if err != nil {
return nil, err
}
decoder := json.NewDecoder(resp.Body)
var res struct {
Domains []Domain `json:"resources"`
}
err = decoder.Decode(&res)
domains = res.Domains
return
}