mirror of https://github.com/rocboss/paopao-ce
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.
38 lines
669 B
38 lines
669 B
3 years ago
|
package app
|
||
|
|
||
|
import (
|
||
|
"github.com/gin-gonic/gin"
|
||
3 years ago
|
"github.com/rocboss/paopao-ce/global"
|
||
|
"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 global.AppSetting.DefaultPageSize
|
||
|
}
|
||
|
if pageSize > global.AppSetting.MaxPageSize {
|
||
|
return global.AppSetting.MaxPageSize
|
||
|
}
|
||
|
|
||
|
return pageSize
|
||
|
}
|
||
|
|
||
|
func GetPageOffset(page, pageSize int) int {
|
||
|
result := 0
|
||
|
if page > 0 {
|
||
|
result = (page - 1) * pageSize
|
||
|
}
|
||
|
|
||
|
return result
|
||
|
}
|