parent
56821c2833
commit
50936924cb
|
@ -38,3 +38,24 @@ func DbPageQuery(database *gorm.DB, query PageQuery, paginationLimit int, result
|
|||
Order(orderBy).
|
||||
Find(result)
|
||||
}
|
||||
|
||||
// GetPage returns start and end for pagination
|
||||
// can be used like this: robots[start:end]
|
||||
func GetPage(lenList int, page int, limit int) (start int, end int) {
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
|
||||
start = (page - 1) * limit
|
||||
end = page * limit
|
||||
|
||||
if start > lenList {
|
||||
start = lenList
|
||||
}
|
||||
|
||||
if end > lenList {
|
||||
end = lenList
|
||||
}
|
||||
|
||||
return start, end
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue