-
Notifications
You must be signed in to change notification settings - Fork 8
/
hosts.go
40 lines (33 loc) · 989 Bytes
/
hosts.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
package request
import (
"encoding/json"
"fmt"
)
// GetHostDetailsRequest represents the request for the details of a
// single private host
type GetHostDetailsRequest struct {
ID int
}
// RequestURL implements the Request interface
func (r *GetHostDetailsRequest) RequestURL() string {
return fmt.Sprintf("/host/%d", r.ID)
}
// ModifyHostRequest represents the request to modify a private host
type ModifyHostRequest struct {
ID int `json:"-"`
Description string `json:"description"`
}
// RequestURL implements the Request interface
func (r *ModifyHostRequest) RequestURL() string {
return fmt.Sprintf("/host/%d", r.ID)
}
// MarshalJSON is a custom marshaller that deals with
// deeply embedded values.
func (r ModifyHostRequest) MarshalJSON() ([]byte, error) {
type localModifyHostRequest ModifyHostRequest
v := struct {
ModifyHostRequest localModifyHostRequest `json:"host"`
}{}
v.ModifyHostRequest = localModifyHostRequest(r)
return json.Marshal(&v)
}