File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -40,6 +40,29 @@ func (s *IPAddresses) UnmarshalJSON(b []byte) error {
4040 return nil
4141}
4242
43+ // IPAddressSlice is a slice of IPAddress.
44+ // It exists to allow for a custom JSON unmarshaller.
45+ type IPAddressSlice []IPAddress
46+
47+ // UnmarshalJSON is a custom unmarshaller that deals with
48+ // deeply embedded values.
49+ func (i * IPAddressSlice ) UnmarshalJSON (b []byte ) error {
50+ type localIPAddress IPAddress
51+ v := struct {
52+ IPAddresses []localIPAddress `json:"ip_address"`
53+ }{}
54+ err := json .Unmarshal (b , & v )
55+ if err != nil {
56+ return err
57+ }
58+
59+ for _ , ip := range v .IPAddresses {
60+ (* i ) = append ((* i ), IPAddress (ip ))
61+ }
62+
63+ return nil
64+ }
65+
4366// IPAddress represents an IP address
4467type IPAddress struct {
4568 Access string `json:"access"`
Original file line number Diff line number Diff line change @@ -116,29 +116,6 @@ type Server struct {
116116 Zone string `json:"zone"`
117117}
118118
119- // IPAddressSlice is a slice of IPAddress.
120- // It exists to allow for a custom JSON unmarshaller.
121- type IPAddressSlice []IPAddress
122-
123- // UnmarshalJSON is a custom unmarshaller that deals with
124- // deeply embedded values.
125- func (i * IPAddressSlice ) UnmarshalJSON (b []byte ) error {
126- type localIPAddress IPAddress
127- v := struct {
128- IPAddresses []localIPAddress `json:"ip_address"`
129- }{}
130- err := json .Unmarshal (b , & v )
131- if err != nil {
132- return err
133- }
134-
135- for _ , ip := range v .IPAddresses {
136- (* i ) = append ((* i ), IPAddress (ip ))
137- }
138-
139- return nil
140- }
141-
142119// ServerStorageDeviceSlice is a slice of ServerStorageDevices.
143120// It exists to allow for a custom JSON unmarshaller.
144121type ServerStorageDeviceSlice []ServerStorageDevice
You can’t perform that action at this time.
0 commit comments