Initial commit.
This commit is contained in:
37
utils/pagination.go
Normal file
37
utils/pagination.go
Normal file
@ -0,0 +1,37 @@
|
||||
package utils
|
||||
|
||||
type OffsetPaginationError struct {
|
||||
Page int
|
||||
Pages int
|
||||
NextPage int
|
||||
LastPage int
|
||||
}
|
||||
|
||||
func (p *OffsetPaginationError) Error() string {
|
||||
return "Not an error, just for offsetbased pagination."
|
||||
}
|
||||
|
||||
func NewOffsetPaginationError(page int, pages int) error {
|
||||
var nextPage int
|
||||
if page+1 <= pages {
|
||||
nextPage = page + 1
|
||||
} else {
|
||||
nextPage = -1
|
||||
}
|
||||
|
||||
return &OffsetPaginationError{Page: page, Pages: pages, NextPage: nextPage, LastPage: page - 1}
|
||||
}
|
||||
|
||||
type KeysetPaginationError struct {
|
||||
Key int
|
||||
NextKey int
|
||||
PreviousKey int
|
||||
}
|
||||
|
||||
func (p *KeysetPaginationError) Error() string {
|
||||
return "Not an error, just for Keysetbased pagination."
|
||||
}
|
||||
|
||||
func NewKeysetPaginationError(key int, next int, previous int) error {
|
||||
return &KeysetPaginationError{Key: key, NextKey: next, PreviousKey: previous}
|
||||
}
|
Reference in New Issue
Block a user