github.com/gophercloud/gophercloud@v1.11.0/openstack/dns/v2/transfer/request/results.go (about) 1 package request 2 3 import ( 4 "encoding/json" 5 "time" 6 7 "github.com/gophercloud/gophercloud" 8 "github.com/gophercloud/gophercloud/pagination" 9 ) 10 11 type commonResult struct { 12 gophercloud.Result 13 } 14 15 // Extract interprets a GetResult, CreateResult or UpdateResult as a TransferRequest. 16 // An error is returned if the original call or the extraction failed. 17 func (r commonResult) Extract() (*TransferRequest, error) { 18 var s *TransferRequest 19 err := r.ExtractInto(&s) 20 return s, err 21 } 22 23 // CreateResult is the result of a Create request. Call its Extract method 24 // to interpret the result as a TransferRequest. 25 type CreateResult struct { 26 commonResult 27 } 28 29 // GetResult is the result of a Get request. Call its Extract method 30 // to interpret the result as a TransferRequest. 31 type GetResult struct { 32 commonResult 33 } 34 35 // UpdateResult is the result of an Update request. Call its Extract method 36 // to interpret the result as a TransferRequest. 37 type UpdateResult struct { 38 commonResult 39 } 40 41 // DeleteResult is the result of a Delete request. Call its ExtractErr method 42 // to determine if the request succeeded or failed. 43 type DeleteResult struct { 44 gophercloud.ErrResult 45 } 46 47 // TransferRequestPage is a single page of TransferRequest results. 48 type TransferRequestPage struct { 49 pagination.LinkedPageBase 50 } 51 52 // IsEmpty returns true if the page contains no results. 53 func (r TransferRequestPage) IsEmpty() (bool, error) { 54 if r.StatusCode == 204 { 55 return true, nil 56 } 57 58 s, err := ExtractTransferRequests(r) 59 return len(s) == 0, err 60 } 61 62 // ExtractTransferRequests extracts a slice of TransferRequest from a List result. 63 func ExtractTransferRequests(r pagination.Page) ([]TransferRequest, error) { 64 var s struct { 65 TransferRequests []TransferRequest `json:"transfer_requests"` 66 } 67 err := (r.(TransferRequestPage)).ExtractInto(&s) 68 return s.TransferRequests, err 69 } 70 71 // TransferRequest represents a Zone transfer request task. 72 type TransferRequest struct { 73 // ID uniquely identifies this transfer request zone amongst all other transfer requests, 74 // including those not accessible to the current tenant. 75 ID string `json:"id"` 76 77 // ZoneID is the ID for the zone that is being exported. 78 ZoneID string `json:"zone_id"` 79 80 // Name is the name of the zone that is being exported. 81 ZoneName string `json:"zone_name"` 82 83 // ProjectID identifies the project/tenant owning this resource. 84 ProjectID string `json:"project_id"` 85 86 // TargetProjectID identifies the project/tenant to transfer this resource. 87 TargetProjectID string `json:"target_project_id"` 88 89 // Key is used as part of the zone transfer accept process. 90 // This is only shown to the creator, and must be communicated out of band. 91 Key string `json:"key"` 92 93 // Description for the resource. 94 Description string `json:"description"` 95 96 // Status is the status of the resource. 97 Status string `json:"status"` 98 99 // CreatedAt is the date when the zone transfer request was created. 100 CreatedAt time.Time `json:"-"` 101 102 // UpdatedAt is the date when the last change was made to the zone transfer request. 103 UpdatedAt time.Time `json:"-"` 104 105 // Links includes HTTP references to the itself, useful for passing along 106 // to other APIs that might want a server reference. 107 Links map[string]interface{} `json:"links"` 108 } 109 110 func (r *TransferRequest) UnmarshalJSON(b []byte) error { 111 type tmp TransferRequest 112 var s struct { 113 tmp 114 CreatedAt gophercloud.JSONRFC3339MilliNoZ `json:"created_at"` 115 UpdatedAt gophercloud.JSONRFC3339MilliNoZ `json:"updated_at"` 116 } 117 err := json.Unmarshal(b, &s) 118 if err != nil { 119 return err 120 } 121 *r = TransferRequest(s.tmp) 122 123 r.CreatedAt = time.Time(s.CreatedAt) 124 r.UpdatedAt = time.Time(s.UpdatedAt) 125 126 return err 127 }