github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v1/routables/results.go (about) 1 package routables 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 // Route represents a route object in a route table 9 type Route struct { 10 Type string `json:"type"` 11 DestinationCIDR string `json:"destination"` 12 NextHop string `json:"nexthop"` 13 Description string `json:"description"` 14 } 15 16 // Subnet represents a subnet object associated with a route table 17 type Subnet struct { 18 ID string `json:"id"` 19 } 20 21 // RouteTable represents a route table 22 type RouteTable struct { 23 // Name is the human readable name for the route table 24 Name string `json:"name"` 25 26 // Description is the supplementary information about the route table 27 Description string `json:"description"` 28 29 // ID is the unique identifier for the route table 30 ID string `json:"id"` 31 32 // the VPC ID that the route table belongs to. 33 VpcID string `json:"vpc_id"` 34 35 // project id 36 TenantID string `json:"tenant_id"` 37 38 // Default indicates whether it is a default route table 39 Default bool `json:"default"` 40 41 // Routes is an array of static routes that the route table will host 42 Routes []Route `json:"routes"` 43 44 // Subnets is an array of subnets that associated with the route table 45 Subnets []Subnet `json:"subnets"` 46 } 47 48 // RouteTablePage is the page returned by a pager when traversing over a 49 // collection of route tables 50 type RouteTablePage struct { 51 pagination.MarkerPageBase 52 } 53 54 // LastMarker returns the last route table ID in a ListResult 55 func (r RouteTablePage) LastMarker() (string, error) { 56 tables, err := ExtractRouteTables(r) 57 if err != nil { 58 return "", err 59 } 60 if len(tables) == 0 { 61 return "", nil 62 } 63 return tables[len(tables)-1].ID, nil 64 } 65 66 // IsEmpty checks whether a RouteTablePage struct is empty. 67 func (r RouteTablePage) IsEmpty() (bool, error) { 68 tables, err := ExtractRouteTables(r) 69 return len(tables) == 0, err 70 } 71 72 // ExtractRouteTables accepts a Page struct, specifically a RouteTablePage struct, 73 // and extracts the elements into a slice of RouteTable structs. 74 func ExtractRouteTables(r pagination.Page) ([]RouteTable, error) { 75 var s struct { 76 RouteTables []RouteTable `json:"routetables"` 77 } 78 err := (r.(RouteTablePage)).ExtractInto(&s) 79 return s.RouteTables, err 80 } 81 82 type commonResult struct { 83 golangsdk.Result 84 } 85 86 // Extract is a function that accepts a result and extracts a route table 87 func (r commonResult) Extract() (*RouteTable, error) { 88 var s struct { 89 RouteTable *RouteTable `json:"routetable"` 90 } 91 err := r.ExtractInto(&s) 92 return s.RouteTable, err 93 } 94 95 // CreateResult represents the result of a create operation. Call its Extract 96 // method to interpret it as a RouteTable 97 type CreateResult struct { 98 commonResult 99 } 100 101 // GetResult represents the result of a get operation. Call its Extract 102 // method to interpret it as a RouteTable 103 type GetResult struct { 104 commonResult 105 } 106 107 // UpdateResult represents the result of an update operation. Call its Extract 108 // method to interpret it as a RouteTable 109 type UpdateResult struct { 110 commonResult 111 } 112 113 // ActionResult represents the result of an action operation. Call its Extract 114 // method to interpret it as a RouteTable 115 type ActionResult struct { 116 commonResult 117 } 118 119 // DeleteResult represents the result of a delete operation. Call its ExtractErr 120 // method to determine if the request succeeded or failed. 121 type DeleteResult struct { 122 golangsdk.ErrResult 123 }