-
Notifications
You must be signed in to change notification settings - Fork 8
/
server_group.go
65 lines (52 loc) · 2.04 KB
/
server_group.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
package upcloud
import "encoding/json"
// ServerAntiAffinityStatus represents the current status of anti affinity setting for a single server. Can be "met" or "unmet"
type ServerAntiAffinityStatus string
const (
ServerAntiAffinityStatusMet ServerAntiAffinityStatus = "met"
ServerAntiAffinityStatusUnmet ServerAntiAffinityStatus = "unmet"
)
// ServerGroupMemberAntiAffinityStatus represents all the data related to an anti affinity status for a single member within the server group
type ServerGroupMemberAntiAffinityStatus struct {
ServerUUID string `json:"uuid"`
Status ServerAntiAffinityStatus `json:"status"`
}
// ServerGroup represents server group
type ServerGroup struct {
Labels LabelSlice `json:"labels,omitempty"`
Members ServerUUIDSlice `json:"servers,omitempty"`
Title string `json:"title,omitempty"`
UUID string `json:"uuid,omitempty"`
AntiAffinity Boolean `json:"anti_affinity,omitempty"`
AntiAffinityStatus []ServerGroupMemberAntiAffinityStatus `json:"anti_affinity_status,omitempty"`
}
// UnmarshalJSON is a custom unmarshaller that deals with deeply embedded values.
func (s *ServerGroup) UnmarshalJSON(b []byte) error {
type sg ServerGroup
v := struct {
ServerGroup sg `json:"server_group"`
}{}
if err := json.Unmarshal(b, &v); err != nil {
return err
}
*s = ServerGroup(v.ServerGroup)
return nil
}
// ServerGroups represents list of server groups
type ServerGroups []ServerGroup
// UnmarshalJSON is a custom unmarshaller that deals with deeply embedded values.
func (s *ServerGroups) UnmarshalJSON(b []byte) error {
type sg ServerGroup
v := struct {
ServerGroups struct {
ServerGroup []sg `json:"server_group"`
} `json:"server_groups"`
}{}
if err := json.Unmarshal(b, &v); err != nil {
return err
}
for _, val := range v.ServerGroups.ServerGroup {
*s = append(*s, ServerGroup(val))
}
return nil
}