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" |
Jon Perritt | 8025197 | 2016-03-09 00:32:30 -0600 | [diff] [blame] | 6 | |
Krzysztof Szukiełojć | 3f41d08 | 2017-05-07 14:43:06 +0200 | [diff] [blame] | 7 | "gerrit.mcp.mirantis.net/debian/gophercloud.git" |
Jon Perritt | c7d828e | 2016-02-25 03:06:33 -0600 | [diff] [blame] | 8 | ) |
| 9 | |
Ash Wilson | c8e6887 | 2014-09-16 10:36:56 -0400 | [diff] [blame] | 10 | // 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] | 11 | type SinglePageBase PageResult |
Ash Wilson | c8e6887 | 2014-09-16 10:36:56 -0400 | [diff] [blame] | 12 | |
| 13 | // NextPageURL always returns "" to indicate that there are no more pages to return. |
| 14 | func (current SinglePageBase) NextPageURL() (string, error) { |
| 15 | return "", nil |
| 16 | } |
Jon Perritt | db319f1 | 2015-02-17 19:32:40 -0700 | [diff] [blame] | 17 | |
Jon Perritt | 8025197 | 2016-03-09 00:32:30 -0600 | [diff] [blame] | 18 | // IsEmpty satisifies the IsEmpty method of the Page interface |
Jon Perritt | c7d828e | 2016-02-25 03:06:33 -0600 | [diff] [blame] | 19 | func (current SinglePageBase) IsEmpty() (bool, error) { |
| 20 | if b, ok := current.Body.([]interface{}); ok { |
| 21 | return len(b) == 0, nil |
| 22 | } |
Jon Perritt | 8025197 | 2016-03-09 00:32:30 -0600 | [diff] [blame] | 23 | err := gophercloud.ErrUnexpectedType{} |
| 24 | err.Expected = "[]interface{}" |
| 25 | err.Actual = fmt.Sprintf("%v", reflect.TypeOf(current.Body)) |
| 26 | return true, err |
Jon Perritt | c7d828e | 2016-02-25 03:06:33 -0600 | [diff] [blame] | 27 | } |
| 28 | |
Jon Perritt | db319f1 | 2015-02-17 19:32:40 -0700 | [diff] [blame] | 29 | // GetBody returns the single page's body. This method is needed to satisfy the |
| 30 | // Page interface. |
| 31 | func (current SinglePageBase) GetBody() interface{} { |
| 32 | return current.Body |
| 33 | } |