blob: 4251d6491efe10bb8ec626c82b6c0560a7045414 [file] [log] [blame]
Ash Wilsonc8e68872014-09-16 10:36:56 -04001package pagination
2
Jon Perrittc7d828e2016-02-25 03:06:33 -06003import (
4 "fmt"
5 "reflect"
Jon Perritt80251972016-03-09 00:32:30 -06006
7 "github.com/gophercloud/gophercloud"
Jon Perrittc7d828e2016-02-25 03:06:33 -06008)
9
Ash Wilsonc8e68872014-09-16 10:36:56 -040010// SinglePageBase may be embedded in a Page that contains all of the results from an operation at once.
Ash Wilsonb8b16f82014-10-20 10:19:49 -040011type SinglePageBase PageResult
Ash Wilsonc8e68872014-09-16 10:36:56 -040012
13// NextPageURL always returns "" to indicate that there are no more pages to return.
14func (current SinglePageBase) NextPageURL() (string, error) {
15 return "", nil
16}
Jon Perrittdb319f12015-02-17 19:32:40 -070017
Jon Perritt80251972016-03-09 00:32:30 -060018// IsEmpty satisifies the IsEmpty method of the Page interface
Jon Perrittc7d828e2016-02-25 03:06:33 -060019func (current SinglePageBase) IsEmpty() (bool, error) {
20 if b, ok := current.Body.([]interface{}); ok {
21 return len(b) == 0, nil
22 }
Jon Perritt80251972016-03-09 00:32:30 -060023 err := gophercloud.ErrUnexpectedType{}
24 err.Expected = "[]interface{}"
25 err.Actual = fmt.Sprintf("%v", reflect.TypeOf(current.Body))
26 return true, err
Jon Perrittc7d828e2016-02-25 03:06:33 -060027}
28
Jon Perrittdb319f12015-02-17 19:32:40 -070029// GetBody returns the single page's body. This method is needed to satisfy the
30// Page interface.
31func (current SinglePageBase) GetBody() interface{} {
32 return current.Body
33}