common.go 527 B

123456789101112131415161718192021222324252627
  1. package middleware
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "strconv"
  5. )
  6. // Common 公共中间件
  7. func Common() gin.HandlerFunc {
  8. return func(c *gin.Context) {
  9. var currPage, pageSize int
  10. reqPage := c.DefaultQuery("curr_page", "0")
  11. currPage, _ = strconv.Atoi(reqPage)
  12. if currPage <= 0 {
  13. currPage = 1
  14. }
  15. reqPageSize := c.DefaultQuery("page_size", "0")
  16. pageSize, _ = strconv.Atoi(reqPageSize)
  17. if pageSize <= 0 {
  18. pageSize = 20
  19. }
  20. c.Set("curr_page", currPage)
  21. c.Set("page_size", pageSize)
  22. c.Next()
  23. }
  24. }