-
Notifications
You must be signed in to change notification settings - Fork 61
/
domain.go
78 lines (67 loc) · 2.08 KB
/
domain.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
package presenter
import (
"net/url"
"code.cloudfoundry.org/korifi/api/repositories"
)
const (
domainsBase = "/v3/domains"
)
type DomainResponse struct {
Name string `json:"name"`
GUID string `json:"guid"`
Internal bool `json:"internal"`
RouterGroup *string `json:"router_group"`
SupportedProtocols []string `json:"supported_protocols"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
Metadata Metadata `json:"metadata"`
Relationships DomainRelationships `json:"relationships"`
Links DomainLinks `json:"links"`
}
type DomainLinks struct {
Self Link `json:"self"`
RouteReservations Link `json:"route_reservations"`
RouterGroup *Link `json:"router_group"`
}
type DomainRelationships struct {
Organization `json:"organization"`
SharedOrganizations `json:"shared_organizations"`
}
type Organization struct {
Data *string `json:"data"`
}
type SharedOrganizations struct {
Data []string `json:"data"`
}
func ForDomain(responseDomain repositories.DomainRecord, baseURL url.URL) DomainResponse {
return DomainResponse{
Name: responseDomain.Name,
GUID: responseDomain.GUID,
Internal: false,
RouterGroup: nil,
SupportedProtocols: []string{"http"},
CreatedAt: formatTimestamp(&responseDomain.CreatedAt),
UpdatedAt: formatTimestamp(responseDomain.UpdatedAt),
Metadata: Metadata{
Labels: emptyMapIfNil(responseDomain.Labels),
Annotations: emptyMapIfNil(responseDomain.Annotations),
},
Relationships: DomainRelationships{
Organization: Organization{
Data: nil,
},
SharedOrganizations: SharedOrganizations{
Data: []string{},
},
},
Links: DomainLinks{
Self: Link{
HRef: buildURL(baseURL).appendPath(domainsBase, responseDomain.GUID).build(),
},
RouteReservations: Link{
HRef: buildURL(baseURL).appendPath(domainsBase, responseDomain.GUID, "route_reservations").build(),
},
RouterGroup: nil,
},
}
}