You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
paopao-ce/pkg/app/pagination.go

45 lines
924 B

3 years ago
package app
import (
"github.com/gin-gonic/gin"
"github.com/rocboss/paopao-ce/internal/conf"
"github.com/rocboss/paopao-ce/pkg/convert"
3 years ago
)
func GetPage(c *gin.Context) int {
page := convert.StrTo(c.Query("page")).MustInt()
if page <= 0 {
return 1
}
return page
}
func GetPageSize(c *gin.Context) int {
pageSize := convert.StrTo(c.Query("page_size")).MustInt()
if pageSize <= 0 {
return conf.AppSetting.DefaultPageSize
3 years ago
}
if pageSize > conf.AppSetting.MaxPageSize {
return conf.AppSetting.MaxPageSize
3 years ago
}
return pageSize
}
func GetPageOffset(c *gin.Context) (offset, limit int) {
page := convert.StrTo(c.Query("page")).MustInt()
if page <= 0 {
page = 1
3 years ago
}
limit = convert.StrTo(c.Query("page_size")).MustInt()
if limit <= 0 {
limit = conf.AppSetting.DefaultPageSize
} else if limit > conf.AppSetting.MaxPageSize {
limit = conf.AppSetting.MaxPageSize
}
offset = (page - 1) * limit
return
3 years ago
}