github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/networking/v2/peeringconnectionrequests/results.go (about) 1 package peeringconnectionrequests 2 3 import ( 4 "encoding/json" 5 6 "github.com/vnpaycloud-console/gophercloud/v2" 7 "github.com/vnpaycloud-console/gophercloud/v2/pagination" 8 ) 9 10 type commonResult struct { 11 gophercloud.Result 12 } 13 14 func (r commonResult) Extract() (*PeeringConnectionRequest, error) { 15 var s PeeringConnectionRequest 16 err := r.ExtractInto(&s) 17 return &s, err 18 } 19 20 func (r commonResult) ExtractInto(v any) error { 21 return r.Result.ExtractIntoStructPtr(v, "peering_connection_request") 22 } 23 24 type CreateResult struct { 25 commonResult 26 } 27 28 type GetResult struct { 29 commonResult 30 } 31 32 type PeeringConnectionRequest struct { 33 ID string `json:"id"` 34 RequestStatus string `json:"request_status"` 35 PeerId string `json:"peering_connection_id"` 36 Description string `json:"description"` 37 ConnectionType string `json:"connection_type"` 38 Status string `json:"status"` 39 VpcId string `json:"src_vpc_id"` 40 PeerOrgId string `json:"dest_org_id"` 41 PeerVpcId string `json:"dest_vpc_id"` 42 } 43 44 func (r *PeeringConnectionRequest) UnmarshalJSON(b []byte) error { 45 type tmp PeeringConnectionRequest 46 var s struct { 47 tmp 48 } 49 50 err := json.Unmarshal(b, &s) 51 52 if err != nil { 53 return err 54 } 55 56 *r = PeeringConnectionRequest(s.tmp) 57 58 return nil 59 } 60 61 type PeeringConnectionRequestPage struct { 62 pagination.LinkedPageBase 63 } 64 65 func (r PeeringConnectionRequestPage) NextPageURL() (string, error) { 66 var s struct { 67 Links []gophercloud.Link `json:"peering_connection_requests_links"` 68 } 69 err := r.ExtractInto(&s) 70 if err != nil { 71 return "", err 72 } 73 return gophercloud.ExtractNextURL(s.Links) 74 } 75 76 func (r PeeringConnectionRequestPage) IsEmpty() (bool, error) { 77 vpcs, err := ExtractPeeringConnectionRequests(r) 78 if err != nil { 79 return true, err 80 } 81 return len(vpcs) == 0, nil 82 } 83 84 func ExtractPeeringConnectionRequests(r pagination.Page) ([]PeeringConnectionRequest, error) { 85 var s []PeeringConnectionRequest 86 err := ExtractPeeringConnectionRequestsInto(r, &s) 87 if err != nil { 88 return nil, err 89 } 90 return s, nil 91 } 92 93 func ExtractPeeringConnectionRequestsInto(r pagination.Page, v any) error { 94 return r.(PeeringConnectionRequestPage).ExtractIntoSlicePtr(v, "peering_connection_requests") 95 }