ch some
This commit is contained in:
@@ -5,22 +5,10 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultPage = 1
|
||||
defaultLimit = 10
|
||||
maxLimit = 100
|
||||
"online-back/internal/shared"
|
||||
)
|
||||
|
||||
func parseID(raw string) (int64, bool) {
|
||||
id, err := strconv.ParseInt(raw, 10, 64)
|
||||
if err != nil || id <= 0 {
|
||||
return 0, false
|
||||
}
|
||||
return id, true
|
||||
}
|
||||
|
||||
func queryValue(c *gin.Context, keys ...string) string {
|
||||
for _, key := range keys {
|
||||
if raw := strings.TrimSpace(c.Query(key)); raw != "" && raw != "undefined" && raw != "null" {
|
||||
@@ -31,8 +19,8 @@ func queryValue(c *gin.Context, keys ...string) string {
|
||||
}
|
||||
|
||||
func parsePageLimit(c *gin.Context) (page, limit int, ok bool) {
|
||||
page = defaultPage
|
||||
limit = defaultLimit
|
||||
page = shared.DefaultPage
|
||||
limit = shared.DefaultLimit
|
||||
|
||||
if raw := queryValue(c, "page"); raw != "" {
|
||||
p, err := strconv.Atoi(raw)
|
||||
@@ -47,8 +35,8 @@ func parsePageLimit(c *gin.Context) (page, limit int, ok bool) {
|
||||
if err != nil || l < 1 {
|
||||
return 0, 0, false
|
||||
}
|
||||
if l > maxLimit {
|
||||
l = maxLimit
|
||||
if l > shared.MaxLimit {
|
||||
l = shared.MaxLimit
|
||||
}
|
||||
limit = l
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user