-
Notifications
You must be signed in to change notification settings - Fork 0
/
results.go
77 lines (64 loc) · 1.46 KB
/
results.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package routes
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
type commonResult struct {
gophercloud.Result
}
type Route struct {
Type string `json:"type"`
Nexthop string `json:"nexthop"`
Destination string `json:"destination"`
VpcID string `json:"vpc_id"`
TenantID string `json:"tenant_id"`
ID string `json:"id"`
}
type CreateResult struct {
commonResult
}
func (r CreateResult) Extract() (*Route, error) {
var entity Route
err := r.ExtractIntoStructPtr(&entity, "route")
return &entity, err
}
type DeleteResult struct {
gophercloud.ErrResult
}
type GetResult struct {
commonResult
}
func (r GetResult) Extract() (*Route, error) {
var entity Route
err := r.ExtractIntoStructPtr(&entity, "route")
return &entity, err
}
type ListResult struct {
commonResult
}
func (r ListResult) Extract() (*[]Route, error) {
var list []Route
err := r.ExtractIntoSlicePtr(&list, "routes")
return &list, err
}
func (r RoutePage) IsEmpty() (bool, error) {
list, err := ExtractRoutes(r)
return len(list) == 0, err
}
type RoutePage struct {
pagination.LinkedPageBase
}
func ExtractRoutes(r pagination.Page) ([]Route, error) {
var s struct {
Routes []Route `json:"routes"`
}
err := r.(RoutePage).ExtractInto(&s)
return s.Routes, err
}
func (r RoutePage) NextPageURL() (string, error) {
s, err := ExtractRoutes(r)
if err != nil {
return "", err
}
return r.WrapNextPageURL(s[len(s)-1].ID)
}