github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/routes/results.go (about) 1 package routes 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 type Route struct { 9 // Specifies the route type. 10 Type string `json:"type"` 11 12 // Specifies the next hop. If the route type is peering, enter the VPC peering connection ID. 13 NextHop string `json:"nexthop"` 14 15 //Specifies the destination IP address or CIDR block. 16 Destination string `json:"destination"` 17 18 // Specifies the VPC for which a route is to be added. 19 VPC_ID string `json:"vpc_id"` 20 21 //Specifies the tenant ID. Only the administrator can specify the tenant ID of other tenants. 22 Tenant_Id string `json:"tenant_id"` 23 24 //Specifies the route ID. 25 RouteID string `json:"id"` 26 } 27 28 // RoutePage is the page returned by a pager when traversing over a 29 // collection of routes. 30 type RoutePage struct { 31 pagination.LinkedPageBase 32 } 33 34 // NextPageURL is invoked when a paginated collection of routes has reached 35 // the end of a page and the pager seeks to traverse over a new one. In order 36 // to do this, it needs to construct the next page's URL. 37 func (r RoutePage) NextPageURL() (string, error) { 38 var s struct { 39 Links []golangsdk.Link `json:"routes_links"` 40 } 41 err := r.ExtractInto(&s) 42 if err != nil { 43 return "", err 44 } 45 return golangsdk.ExtractNextURL(s.Links) 46 } 47 48 // IsEmpty checks whether a RoutePage struct is empty. 49 func (r RoutePage) IsEmpty() (bool, error) { 50 is, err := ExtractRoutes(r) 51 return len(is) == 0, err 52 } 53 54 // ExtractRoutes accepts a Page struct, specifically a RoutePage struct, 55 // and extracts the elements into a slice of Roue structs. In other words, 56 // a generic collection is mapped into a relevant slice. 57 func ExtractRoutes(r pagination.Page) ([]Route, error) { 58 var s struct { 59 Routes []Route `json:"routes"` 60 } 61 err := (r.(RoutePage)).ExtractInto(&s) 62 return s.Routes, err 63 } 64 65 type commonResult struct { 66 golangsdk.Result 67 } 68 69 // Extract is a function that accepts a result and extracts a Route. 70 func (r commonResult) Extract() (*Route, error) { 71 var s struct { 72 Route *Route `json:"route"` 73 } 74 err := r.ExtractInto(&s) 75 return s.Route, err 76 } 77 78 // CreateResult represents the result of a create operation. Call its Extract 79 // method to interpret it as a Route. 80 type CreateResult struct { 81 commonResult 82 } 83 84 // GetResult represents the result of a get operation. Call its Extract 85 // method to interpret it as a Route. 86 type GetResult struct { 87 commonResult 88 } 89 90 // DeleteResult represents the result of a delete operation. Call its ExtractErr 91 // method to determine if the request succeeded or failed. 92 type DeleteResult struct { 93 golangsdk.ErrResult 94 }