github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/pagination/single.go (about)

     1  package pagination
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  // SinglePageBase may be embedded in a Page that contains all the results from an operation at once.
     8  // Deprecated: use element slice as a return result.
     9  type SinglePageBase PageResult
    10  
    11  func (current SinglePageBase) GetBody() []byte {
    12  	return current.Body
    13  }
    14  
    15  func (current SinglePageBase) GetBodyAsSlice() ([]interface{}, error) {
    16  	return PageResult(current).GetBodyAsSlice()
    17  }
    18  
    19  func (current SinglePageBase) GetBodyAsMap() (map[string]interface{}, error) {
    20  	return PageResult(current).GetBodyAsMap()
    21  }
    22  
    23  // NextPageURL always returns "" to indicate that there are no more pages to return.
    24  func (current SinglePageBase) NextPageURL() (string, error) {
    25  	return "", nil
    26  }
    27  
    28  // IsEmpty satisfies the IsEmpty method of the Page interface
    29  func (current SinglePageBase) IsEmpty() (bool, error) {
    30  	body, err := current.GetBodyAsSlice()
    31  	if err != nil {
    32  		return false, fmt.Errorf("error converting page body to slice: %w", err)
    33  	}
    34  
    35  	return len(body) == 0, nil
    36  }
    37  
    38  // NewSinglePageBase may be embedded in a Page that contains all the results from an operation at once.
    39  type NewSinglePageBase struct {
    40  	NewPageResult
    41  }
    42  
    43  // NewNextPageURL always returns "" to indicate that there are no more pages to return.
    44  func (current NewSinglePageBase) NewNextPageURL() (string, error) {
    45  	return "", nil
    46  }
    47  
    48  // NewIsEmpty satisfies the IsEmpty method of the Page interface
    49  func (current NewSinglePageBase) NewIsEmpty() (bool, error) {
    50  	body, err := current.NewGetBodyAsSlice()
    51  	if err != nil {
    52  		return false, fmt.Errorf("error converting page body to slice: %w", err)
    53  	}
    54  
    55  	return len(body) == 0, nil
    56  }