Ash Wilson | c8e6887 | 2014-09-16 10:36:56 -0400 | [diff] [blame] | 1 | package pagination |
| 2 | |
Jon Perritt | c7d828e | 2016-02-25 03:06:33 -0600 | [diff] [blame] | 3 | import ( |
| 4 | "fmt" |
| 5 | "reflect" |
| 6 | ) |
| 7 | |
Ash Wilson | c8e6887 | 2014-09-16 10:36:56 -0400 | [diff] [blame] | 8 | // SinglePageBase may be embedded in a Page that contains all of the results from an operation at once. |
Ash Wilson | b8b16f8 | 2014-10-20 10:19:49 -0400 | [diff] [blame] | 9 | type SinglePageBase PageResult |
Ash Wilson | c8e6887 | 2014-09-16 10:36:56 -0400 | [diff] [blame] | 10 | |
| 11 | // NextPageURL always returns "" to indicate that there are no more pages to return. |
| 12 | func (current SinglePageBase) NextPageURL() (string, error) { |
| 13 | return "", nil |
| 14 | } |
Jon Perritt | db319f1 | 2015-02-17 19:32:40 -0700 | [diff] [blame] | 15 | |
Jon Perritt | c7d828e | 2016-02-25 03:06:33 -0600 | [diff] [blame] | 16 | func (current SinglePageBase) IsEmpty() (bool, error) { |
| 17 | if b, ok := current.Body.([]interface{}); ok { |
| 18 | return len(b) == 0, nil |
| 19 | } |
| 20 | return true, fmt.Errorf("Error while checking if SinglePageBase was empty: expected []interface type for Body bot got %+v", reflect.TypeOf(current.Body)) |
| 21 | } |
| 22 | |
Jon Perritt | db319f1 | 2015-02-17 19:32:40 -0700 | [diff] [blame] | 23 | // GetBody returns the single page's body. This method is needed to satisfy the |
| 24 | // Page interface. |
| 25 | func (current SinglePageBase) GetBody() interface{} { |
| 26 | return current.Body |
| 27 | } |