Files
0451meishi/backend/internal/handlers/pagination.go
2026-01-15 11:37:22 +08:00

24 lines
399 B
Go

package handlers
import "strconv"
func parsePage(pageStr, sizeStr string) (int, int) {
page, _ := strconv.Atoi(pageStr)
size, _ := strconv.Atoi(sizeStr)
if page < 1 {
page = 1
}
if size < 1 || size > 200 {
size = 20
}
return page, size
}
func calcTotalPage(total int64, pageSize int) int64 {
if pageSize <= 0 {
return 0
}
return (total + int64(pageSize) - 1) / int64(pageSize)
}