forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdomain_resource.go
69 lines (57 loc) · 1.8 KB
/
domain_resource.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
package resources
import (
"code.cloudfoundry.org/cli/types"
"code.cloudfoundry.org/jsonry"
)
type Domain struct {
GUID string `json:"guid,omitempty"`
Name string `json:"name"`
Internal types.NullBool `json:"internal,omitempty"`
OrganizationGUID string `jsonry:"relationships.organization.data.guid,omitempty"`
RouterGroup string `jsonry:"router_group.guid,omitempty"`
Protocols []string `jsonry:"supported_protocols,omitempty"`
// Metadata is used for custom tagging of API resources
Metadata *Metadata `json:"metadata,omitempty"`
}
func (d Domain) MarshalJSON() ([]byte, error) {
type domainWithBoolPointer struct {
GUID string `jsonry:"guid,omitempty"`
Name string `jsonry:"name"`
Internal *bool `jsonry:"internal,omitempty"`
OrganizationGUID string `jsonry:"relationships.organization.data.guid,omitempty"`
RouterGroup string `jsonry:"router_group.guid,omitempty"`
Protocols []string `jsonry:"supported_protocols,omitempty"`
}
clone := domainWithBoolPointer{
GUID: d.GUID,
Name: d.Name,
OrganizationGUID: d.OrganizationGUID,
RouterGroup: d.RouterGroup,
Protocols: d.Protocols,
}
if d.Internal.IsSet {
clone.Internal = &d.Internal.Value
}
return jsonry.Marshal(clone)
}
func (d *Domain) UnmarshalJSON(data []byte) error {
type alias Domain
var defaultUnmarshalledDomain alias
err := jsonry.Unmarshal(data, &defaultUnmarshalledDomain)
if err != nil {
return err
}
*d = Domain(defaultUnmarshalledDomain)
return nil
}
func (d Domain) Shared() bool {
return d.OrganizationGUID == ""
}
func (d *Domain) IsTCP() bool {
for _, p := range d.Protocols {
if p == "tcp" {
return true
}
}
return false
}