github.com/gophercloud/gophercloud@v1.11.0/openstack/dns/v2/transfer/accept/results.go (about) 1 package accept 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 as a TransferAccept. 16 // An error is returned if the original call or the extraction failed. 17 func (r commonResult) Extract() (*TransferAccept, error) { 18 var s *TransferAccept 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 TransferAccept. 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 TransferAccept. 31 type GetResult struct { 32 commonResult 33 } 34 35 // TransferAcceptPage is a single page of TransferAccept results. 36 type TransferAcceptPage struct { 37 pagination.LinkedPageBase 38 } 39 40 // IsEmpty returns true if the page contains no results. 41 func (r TransferAcceptPage) IsEmpty() (bool, error) { 42 if r.StatusCode == 204 { 43 return true, nil 44 } 45 46 s, err := ExtractTransferAccepts(r) 47 return len(s) == 0, err 48 } 49 50 // ExtractTransferAccepts extracts a slice of TransferAccept from a List result. 51 func ExtractTransferAccepts(r pagination.Page) ([]TransferAccept, error) { 52 var s struct { 53 TransferAccepts []TransferAccept `json:"transfer_accepts"` 54 } 55 err := (r.(TransferAcceptPage)).ExtractInto(&s) 56 return s.TransferAccepts, err 57 } 58 59 // TransferAccept represents a Zone transfer accept task. 60 type TransferAccept struct { 61 // ID for this zone transfer accept. 62 ID string `json:"id"` 63 64 // Status is current status of the zone transfer request. 65 Status string `json:"status"` 66 67 // ProjectID identifies the project/tenant owning this resource. 68 ProjectID string `json:"project_id"` 69 70 // ZoneID is the ID for the zone that was being exported. 71 ZoneID string `json:"zone_id"` 72 73 // Key is used as part of the zone transfer accept process. 74 // This is only shown to the creator, and must be communicated out of band. 75 Key string `json:"key"` 76 77 // ZoneTransferRequestID is ID for this zone transfer request 78 ZoneTransferRequestID string `json:"zone_transfer_request_id"` 79 80 // CreatedAt is the date when the zone transfer accept was created. 81 CreatedAt time.Time `json:"-"` 82 83 // UpdatedAt is the date when the last change was made to the zone transfer accept. 84 UpdatedAt time.Time `json:"-"` 85 86 // Links includes HTTP references to the itself, useful for passing along 87 // to other APIs that might want a server reference. 88 Links map[string]interface{} `json:"links"` 89 } 90 91 func (r *TransferAccept) UnmarshalJSON(b []byte) error { 92 type tmp TransferAccept 93 var s struct { 94 tmp 95 CreatedAt gophercloud.JSONRFC3339MilliNoZ `json:"created_at"` 96 UpdatedAt gophercloud.JSONRFC3339MilliNoZ `json:"updated_at"` 97 } 98 err := json.Unmarshal(b, &s) 99 if err != nil { 100 return err 101 } 102 *r = TransferAccept(s.tmp) 103 104 r.CreatedAt = time.Time(s.CreatedAt) 105 r.UpdatedAt = time.Time(s.UpdatedAt) 106 107 return err 108 }