7 "github.com/gophercloud/gophercloud"
10 // LinkedPageBase may be embedded to implement a page that provides navigational "Next" and "Previous" links within its result.
11 type LinkedPageBase struct {
14 // LinkPath lists the keys that should be traversed within a response to arrive at the "next" pointer.
15 // If any link along the path is missing, an empty URL will be returned.
16 // If any link results in an unexpected value type, an error will be returned.
17 // When left as "nil", []string{"links", "next"} will be used as a default.
21 // NextPageURL extracts the pagination structure from a JSON response and returns the "next" link, if one is present.
22 // It assumes that the links are available in a "links" element of the top-level response object.
23 // If this is not the case, override NextPageURL on your result type.
24 func (current LinkedPageBase) NextPageURL() (string, error) {
28 if current.LinkPath == nil {
29 path = []string{"links", "next"}
31 path = current.LinkPath
34 submap, ok := current.Body.(map[string]interface{})
36 err := gophercloud.ErrUnexpectedType{}
37 err.Expected = "map[string]interface{}"
38 err.Actual = fmt.Sprintf("%v", reflect.TypeOf(current.Body))
43 key, path = path[0], path[1:len(path)]
45 value, ok := submap[key]
51 submap, ok = value.(map[string]interface{})
53 err := gophercloud.ErrUnexpectedType{}
54 err.Expected = "map[string]interface{}"
55 err.Actual = fmt.Sprintf("%v", reflect.TypeOf(value))
60 // Actual null element.
64 url, ok := value.(string)
66 err := gophercloud.ErrUnexpectedType{}
67 err.Expected = "string"
68 err.Actual = fmt.Sprintf("%v", reflect.TypeOf(value))
77 // IsEmpty satisifies the IsEmpty method of the Page interface
78 func (current LinkedPageBase) IsEmpty() (bool, error) {
79 if b, ok := current.Body.([]interface{}); ok {
80 return len(b) == 0, nil
82 err := gophercloud.ErrUnexpectedType{}
83 err.Expected = "[]interface{}"
84 err.Actual = fmt.Sprintf("%v", reflect.TypeOf(current.Body))
88 // GetBody returns the linked page's body. This method is needed to satisfy the
90 func (current LinkedPageBase) GetBody() interface{} {