123456789101112131415161718192021222324252627 |
- package middleware
- import (
- "github.com/gin-gonic/gin"
- "strconv"
- )
- // Common 公共中间件
- func Common() gin.HandlerFunc {
- return func(c *gin.Context) {
- var currPage, pageSize int
- reqPage := c.DefaultQuery("curr_page", "0")
- currPage, _ = strconv.Atoi(reqPage)
- if currPage <= 0 {
- currPage = 1
- }
- reqPageSize := c.DefaultQuery("page_size", "0")
- pageSize, _ = strconv.Atoi(reqPageSize)
- if pageSize <= 0 {
- pageSize = 20
- }
- c.Set("curr_page", currPage)
- c.Set("page_size", pageSize)
- c.Next()
- }
- }
|