@ -10,7 +10,7 @@ import (
)
)
// ParsePaginator parses a db.Paginator into a skip and limit
// ParsePaginator parses a db.Paginator into a skip and limit
func ParsePaginator ( paginator db . Paginator , max ... int ) ( int , int ) {
func ParsePaginator ( paginator * db . ListOptions , max ... int ) ( int , int ) {
// Use a very large number to indicate no limit
// Use a very large number to indicate no limit
unlimited := math . MaxInt32
unlimited := math . MaxInt32
if len ( max ) > 0 {
if len ( max ) > 0 {
@ -19,22 +19,15 @@ func ParsePaginator(paginator db.Paginator, max ...int) (int, int) {
}
}
if paginator == nil || paginator . IsListAll ( ) {
if paginator == nil || paginator . IsListAll ( ) {
// It shouldn't happen. In actual usage scenarios, there should not be requests to search all.
// But if it does happen, respect it and return "unlimited".
// And it's also useful for testing.
return 0 , unlimited
return 0 , unlimited
}
}
// Warning: Do not use GetSkipTake() for *db.ListOptions
if paginator . PageSize == 0 {
// Its implementation could reset the page size with setting.API.MaxResponseItems
// Do not return any results when searching, it's used to get the total count only.
if listOptions , ok := paginator . ( * db . ListOptions ) ; ok {
return 0 , 0
if listOptions . Page >= 0 && listOptions . PageSize > 0 {
var start int
if listOptions . Page == 0 {
start = 0
} else {
start = ( listOptions . Page - 1 ) * listOptions . PageSize
}
return start , listOptions . PageSize
}
return 0 , unlimited
}
}
return paginator . GetSkipTake ( )
return paginator . GetSkipTake ( )