added get page

main v1.0.13
alex 2023-10-13 16:11:02 +02:00
parent 56821c2833
commit 50936924cb
1 changed files with 21 additions and 0 deletions

View File

@ -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
}