github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/pagination/single.go (about)

     1  package pagination
     2  
     3  import (
     4  	"fmt"
     5  	"reflect"
     6  
     7  	"github.com/huaweicloud/golangsdk"
     8  )
     9  
    10  // SinglePageBase may be embedded in a Page that contains all of the results from an operation at once.
    11  type SinglePageBase PageResult
    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  }
    17  
    18  // IsEmpty satisifies the IsEmpty method of the Page interface
    19  func (current SinglePageBase) IsEmpty() (bool, error) {
    20  	if b, ok := current.Body.([]interface{}); ok {
    21  		return len(b) == 0, nil
    22  	}
    23  	err := golangsdk.ErrUnexpectedType{}
    24  	err.Expected = "[]interface{}"
    25  	err.Actual = fmt.Sprintf("%v", reflect.TypeOf(current.Body))
    26  	return true, err
    27  }
    28  
    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  }