github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/networking/v2/peeringconnections/results.go (about) 1 package peeringconnections 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() (*PeeringConnection, error) { 15 var s PeeringConnection 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") 22 } 23 24 type GetResult struct { 25 commonResult 26 } 27 28 type UpdateResult struct { 29 commonResult 30 } 31 32 type DeleteResult struct { 33 gophercloud.ErrResult 34 } 35 36 type PeeringConnection struct { 37 ID string `json:"id"` 38 PeerStatus string `json:"peering_status"` 39 Description string `json:"description"` 40 ConnectionType string `json:"connection_type"` 41 Status string `json:"status"` 42 VpcId string `json:"src_vpc_id"` 43 PeerOrgId string `json:"dest_org_id"` 44 PeerVpcId string `json:"dest_vpc_id"` 45 } 46 47 func (r *PeeringConnection) UnmarshalJSON(b []byte) error { 48 type tmp PeeringConnection 49 var s struct { 50 tmp 51 } 52 53 err := json.Unmarshal(b, &s) 54 55 if err != nil { 56 return err 57 } 58 59 *r = PeeringConnection(s.tmp) 60 61 return nil 62 } 63 64 type PeeringConnectionPage struct { 65 pagination.LinkedPageBase 66 } 67 68 func (r PeeringConnectionPage) NextPageURL() (string, error) { 69 var s struct { 70 Links []gophercloud.Link `json:"peering_connections_links"` 71 } 72 err := r.ExtractInto(&s) 73 if err != nil { 74 return "", err 75 } 76 return gophercloud.ExtractNextURL(s.Links) 77 } 78 79 func (r PeeringConnectionPage) IsEmpty() (bool, error) { 80 peeringConnections, err := ExtractPeeringConnections(r) 81 if err != nil { 82 return true, err 83 } 84 return len(peeringConnections) == 0, nil 85 } 86 87 func ExtractPeeringConnections(r pagination.Page) ([]PeeringConnection, error) { 88 var s []PeeringConnection 89 err := ExtractPeeringConnectionsInto(r, &s) 90 if err != nil { 91 return nil, err 92 } 93 return s, nil 94 } 95 96 func ExtractPeeringConnectionsInto(r pagination.Page, v any) error { 97 return r.(PeeringConnectionPage).ExtractIntoSlicePtr(v, "peering_connections") 98 }