-
Notifications
You must be signed in to change notification settings - Fork 510
/
results.go
127 lines (101 loc) · 3.57 KB
/
results.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package request
import (
"encoding/json"
"time"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
type commonResult struct {
gophercloud.Result
}
// Extract interprets a GetResult, CreateResult or UpdateResult as a TransferRequest.
// An error is returned if the original call or the extraction failed.
func (r commonResult) Extract() (*TransferRequest, error) {
var s *TransferRequest
err := r.ExtractInto(&s)
return s, err
}
// CreateResult is the result of a Create request. Call its Extract method
// to interpret the result as a TransferRequest.
type CreateResult struct {
commonResult
}
// GetResult is the result of a Get request. Call its Extract method
// to interpret the result as a TransferRequest.
type GetResult struct {
commonResult
}
// UpdateResult is the result of an Update request. Call its Extract method
// to interpret the result as a TransferRequest.
type UpdateResult struct {
commonResult
}
// DeleteResult is the result of a Delete request. Call its ExtractErr method
// to determine if the request succeeded or failed.
type DeleteResult struct {
gophercloud.ErrResult
}
// TransferRequestPage is a single page of TransferRequest results.
type TransferRequestPage struct {
pagination.LinkedPageBase
}
// IsEmpty returns true if the page contains no results.
func (r TransferRequestPage) IsEmpty() (bool, error) {
if r.StatusCode == 204 {
return true, nil
}
s, err := ExtractTransferRequests(r)
return len(s) == 0, err
}
// ExtractTransferRequests extracts a slice of TransferRequest from a List result.
func ExtractTransferRequests(r pagination.Page) ([]TransferRequest, error) {
var s struct {
TransferRequests []TransferRequest `json:"transfer_requests"`
}
err := (r.(TransferRequestPage)).ExtractInto(&s)
return s.TransferRequests, err
}
// TransferRequest represents a Zone transfer request task.
type TransferRequest struct {
// ID uniquely identifies this transfer request zone amongst all other transfer requests,
// including those not accessible to the current tenant.
ID string `json:"id"`
// ZoneID is the ID for the zone that is being exported.
ZoneID string `json:"zone_id"`
// Name is the name of the zone that is being exported.
ZoneName string `json:"zone_name"`
// ProjectID identifies the project/tenant owning this resource.
ProjectID string `json:"project_id"`
// TargetProjectID identifies the project/tenant to transfer this resource.
TargetProjectID string `json:"target_project_id"`
// Key is used as part of the zone transfer accept process.
// This is only shown to the creator, and must be communicated out of band.
Key string `json:"key"`
// Description for the resource.
Description string `json:"description"`
// Status is the status of the resource.
Status string `json:"status"`
// CreatedAt is the date when the zone transfer request was created.
CreatedAt time.Time `json:"-"`
// UpdatedAt is the date when the last change was made to the zone transfer request.
UpdatedAt time.Time `json:"-"`
// Links includes HTTP references to the itself, useful for passing along
// to other APIs that might want a server reference.
Links map[string]interface{} `json:"links"`
}
func (r *TransferRequest) UnmarshalJSON(b []byte) error {
type tmp TransferRequest
var s struct {
tmp
CreatedAt gophercloud.JSONRFC3339MilliNoZ `json:"created_at"`
UpdatedAt gophercloud.JSONRFC3339MilliNoZ `json:"updated_at"`
}
err := json.Unmarshal(b, &s)
if err != nil {
return err
}
*r = TransferRequest(s.tmp)
r.CreatedAt = time.Time(s.CreatedAt)
r.UpdatedAt = time.Time(s.UpdatedAt)
return err
}