Remove BPA from Makefile
[icn.git] / cmd / bpa-operator / vendor / github.com / gophercloud / gophercloud / pagination / marker.go
1 package pagination
2
3 import (
4         "fmt"
5         "reflect"
6
7         "github.com/gophercloud/gophercloud"
8 )
9
10 // MarkerPage is a stricter Page interface that describes additional functionality required for use with NewMarkerPager.
11 // For convenience, embed the MarkedPageBase struct.
12 type MarkerPage interface {
13         Page
14
15         // LastMarker returns the last "marker" value on this page.
16         LastMarker() (string, error)
17 }
18
19 // MarkerPageBase is a page in a collection that's paginated by "limit" and "marker" query parameters.
20 type MarkerPageBase struct {
21         PageResult
22
23         // Owner is a reference to the embedding struct.
24         Owner MarkerPage
25 }
26
27 // NextPageURL generates the URL for the page of results after this one.
28 func (current MarkerPageBase) NextPageURL() (string, error) {
29         currentURL := current.URL
30
31         mark, err := current.Owner.LastMarker()
32         if err != nil {
33                 return "", err
34         }
35
36         q := currentURL.Query()
37         q.Set("marker", mark)
38         currentURL.RawQuery = q.Encode()
39
40         return currentURL.String(), nil
41 }
42
43 // IsEmpty satisifies the IsEmpty method of the Page interface
44 func (current MarkerPageBase) IsEmpty() (bool, error) {
45         if b, ok := current.Body.([]interface{}); ok {
46                 return len(b) == 0, nil
47         }
48         err := gophercloud.ErrUnexpectedType{}
49         err.Expected = "[]interface{}"
50         err.Actual = fmt.Sprintf("%v", reflect.TypeOf(current.Body))
51         return true, err
52 }
53
54 // GetBody returns the linked page's body. This method is needed to satisfy the
55 // Page interface.
56 func (current MarkerPageBase) GetBody() interface{} {
57         return current.Body
58 }