@@ -33,8 +33,12 @@ func (r *GetServerDetailsRequest) RequestURL() string {
3333 return fmt .Sprintf ("/server/%s" , r .UUID )
3434}
3535
36+ // CreateServerIPAddressSlice is a slice of strings
37+ // It exists to allow for a custom JSON marshaller.
3638type CreateServerIPAddressSlice []CreateServerIPAddress
3739
40+ // MarshalJSON is a custom marshaller that deals with
41+ // deeply embedded values.
3842func (s CreateServerIPAddressSlice ) MarshalJSON () ([]byte , error ) {
3943 v := struct {
4044 IPAddress []CreateServerIPAddress `json:"ip_address"`
@@ -44,8 +48,12 @@ func (s CreateServerIPAddressSlice) MarshalJSON() ([]byte, error) {
4448 return json .Marshal (v )
4549}
4650
51+ // CreateServerStorageDeviceSlice is a slice of strings
52+ // It exists to allow for a custom JSON marshaller.
4753type CreateServerStorageDeviceSlice []upcloud.CreateServerStorageDevice
4854
55+ // MarshalJSON is a custom marshaller that deals with
56+ // deeply embedded values.
4957func (s CreateServerStorageDeviceSlice ) MarshalJSON () ([]byte , error ) {
5058 v := struct {
5159 StorageDevice []upcloud.CreateServerStorageDevice `json:"storage_device"`
@@ -81,6 +89,8 @@ type CreateServerRequest struct {
8189 Zone string `xml:"zone" json:"zone"`
8290}
8391
92+ // MarshalJSON is a custom marshaller that deals with
93+ // deeply embedded values.
8494func (r CreateServerRequest ) MarshalJSON () ([]byte , error ) {
8595 type localCreateServerRequest CreateServerRequest
8696 v := struct {
@@ -96,8 +106,12 @@ func (r *CreateServerRequest) RequestURL() string {
96106 return "/server"
97107}
98108
109+ // SSHKeySlice is a slice of strings
110+ // It exists to allow for a custom JSON unmarshaller.
99111type SSHKeySlice []string
100112
113+ // UnmarshalJSON is a custom unmarshaller that deals with
114+ // deeply embedded values.
101115func (s * SSHKeySlice ) UnmarshalJSON (b []byte ) error {
102116 v := struct {
103117 SSHKey []string `json:"ssh_key"`
@@ -112,6 +126,8 @@ func (s *SSHKeySlice) UnmarshalJSON(b []byte) error {
112126 return nil
113127}
114128
129+ // MarshalJSON is a custom marshaller that deals with
130+ // deeply embedded values.
115131func (s SSHKeySlice ) MarshalJSON () ([]byte , error ) {
116132 v := struct {
117133 SSHKey []string `json:"ssh_key"`
@@ -158,19 +174,32 @@ func (r *StartServerRequest) RequestURL() string {
158174
159175// StopServerRequest represents a request to stop a server
160176type StopServerRequest struct {
161- XMLName xml.Name `xml:"stop_server"`
177+ XMLName xml.Name `xml:"stop_server" json:"-" `
162178
163- UUID string `xml:"-"`
179+ UUID string `xml:"-" json:"-" `
164180
165- StopType string `xml:"stop_type,omitempty"`
166- Timeout time.Duration `xml:"timeout,omitempty"`
181+ StopType string `xml:"stop_type,omitempty" json:"stop_type,omitempty" `
182+ Timeout time.Duration `xml:"timeout,omitempty" json:"timeout,omitempty,string" `
167183}
168184
169185// RequestURL implements the Request interface
170186func (r * StopServerRequest ) RequestURL () string {
171187 return fmt .Sprintf ("/server/%s/stop" , r .UUID )
172188}
173189
190+ // MarshalJSON is a custom marshaller that deals with
191+ // deeply embedded values.
192+ func (r StopServerRequest ) MarshalJSON () ([]byte , error ) {
193+ type localStopServerRequest StopServerRequest
194+ v := struct {
195+ StopServerRequest localStopServerRequest `json:"stop_server"`
196+ }{}
197+ v .StopServerRequest = localStopServerRequest (r )
198+ v .StopServerRequest .Timeout = v .StopServerRequest .Timeout / 1e9
199+
200+ return json .Marshal (& v )
201+ }
202+
174203// MarshalXML implements a custom marshaller for StopServerRequest which converts the timeout to seconds
175204func (r * StopServerRequest ) MarshalXML (e * xml.Encoder , start xml.StartElement ) error {
176205 type Alias StopServerRequest
@@ -186,20 +215,33 @@ func (r *StopServerRequest) MarshalXML(e *xml.Encoder, start xml.StartElement) e
186215
187216// RestartServerRequest represents a request to restart a server
188217type RestartServerRequest struct {
189- XMLName xml.Name `xml:"restart_server"`
218+ XMLName xml.Name `xml:"restart_server" json:"-" `
190219
191- UUID string `xml:"-"`
220+ UUID string `xml:"-" json:"-" `
192221
193- StopType string `xml:"stop_type,omitempty"`
194- Timeout time.Duration `xml:"timeout,omitempty"`
195- TimeoutAction string `xml:"timeout_action,omitempty"`
222+ StopType string `xml:"stop_type,omitempty" json:"stop_type,omitempty" `
223+ Timeout time.Duration `xml:"timeout,omitempty" json:"timeout,omitempty,string" `
224+ TimeoutAction string `xml:"timeout_action,omitempty" json:"timeout_action,omitempty" `
196225}
197226
198227// RequestURL implements the Request interface
199228func (r * RestartServerRequest ) RequestURL () string {
200229 return fmt .Sprintf ("/server/%s/restart" , r .UUID )
201230}
202231
232+ // MarshalJSON is a custom marshaller that deals with
233+ // deeply embedded values.
234+ func (r RestartServerRequest ) MarshalJSON () ([]byte , error ) {
235+ type localRestartServerRequest RestartServerRequest
236+ v := struct {
237+ RestartServerRequest localRestartServerRequest `json:"restart_server"`
238+ }{}
239+ v .RestartServerRequest = localRestartServerRequest (r )
240+ v .RestartServerRequest .Timeout = v .RestartServerRequest .Timeout / 1e9
241+
242+ return json .Marshal (& v )
243+ }
244+
203245// MarshalXML implements a custom marshaller for RestartServerRequest which converts the timeout to seconds
204246func (r * RestartServerRequest ) MarshalXML (e * xml.Encoder , start xml.StartElement ) error {
205247 type Alias RestartServerRequest
@@ -215,26 +257,36 @@ func (r *RestartServerRequest) MarshalXML(e *xml.Encoder, start xml.StartElement
215257
216258// ModifyServerRequest represents a request to modify a server
217259type ModifyServerRequest struct {
218- XMLName xml.Name `xml:"server"`
260+ XMLName xml.Name `xml:"server" json:"-" `
219261
220- UUID string `xml:"-"`
262+ UUID string `xml:"-" json:"-" `
221263
222- AvoidHost string `xml:"avoid_host,omitempty"`
223- BootOrder string `xml:"boot_order,omitempty"`
224- // TODO: Investigate correct type and format
225- CoreNumber string `xml:"core_number,omitempty"`
264+ AvoidHost string `xml:"avoid_host,omitempty" json:"avoid_host,omitempty"`
265+ BootOrder string `xml:"boot_order,omitempty" json:"boot_order,omitempty"`
266+ CoreNumber int `xml:"core_number,omitempty" json:"core_number,omitempty,string"`
226267 // TODO: Convert to boolean
227- Firewall string `xml:"firewall,omitempty"`
228- Hostname string `xml:"hostname,omitempty"`
229- // TODO: Investigate correct type and format
230- MemoryAmount string `xml:"memory_amount,omitempty"`
231- Plan string `xml:"plan,omitempty"`
232- TimeZone string `xml:"timezone,omitempty"`
233- Title string `xml:"title,omitempty"`
234- VideoModel string `xml:"video_model,omitempty"`
268+ Firewall string `xml:"firewall,omitempty" json:"firewall,omitempty"`
269+ Hostname string `xml:"hostname,omitempty" json:"hostname,omitempty"`
270+ MemoryAmount int `xml:"memory_amount,omitempty" json:"memory_amount,omitempty,string"`
271+ Plan string `xml:"plan,omitempty" json:"plan,omitempty"`
272+ TimeZone string `xml:"timezone,omitempty" json:"timezone,omitempty"`
273+ Title string `xml:"title,omitempty" json:"title,omitempty"`
274+ VideoModel string `xml:"video_model,omitempty" json:"video_model,omitempty"`
235275 // TODO: Convert to boolean
236- VNC string `xml:"vnc,omitempty"`
237- VNCPassword string `xml:"vnc_password,omitempty"`
276+ VNC string `xml:"vnc,omitempty" json:"vnc,omitempty"`
277+ VNCPassword string `xml:"vnc_password,omitempty" json:"vnc_password,omitempty"`
278+ }
279+
280+ // MarshalJSON is a custom marshaller that deals with
281+ // deeply embedded values.
282+ func (r ModifyServerRequest ) MarshalJSON () ([]byte , error ) {
283+ type localModifyServerRequest ModifyServerRequest
284+ v := struct {
285+ ModifyServerRequest localModifyServerRequest `json:"server"`
286+ }{}
287+ v .ModifyServerRequest = localModifyServerRequest (r )
288+
289+ return json .Marshal (& v )
238290}
239291
240292// RequestURL implements the Request interface
0 commit comments