12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- package middleware
- import (
- "bytes"
- "fmt"
- "github.com/gin-gonic/gin"
- "hongze/hongze_yb/utils"
- "io"
- "net/http"
- "strconv"
- )
- type Common struct{}
- func (common *Common) RequestLog(c *gin.Context) {
-
- body, err := io.ReadAll(c.Request.Body)
- if err != nil {
-
- c.AbortWithStatus(http.StatusInternalServerError)
- return
- }
-
- utils.SetContextLogListByClaims(c, fmt.Sprint("Url:", c.Request.RequestURI))
-
- utils.SetContextLogListByClaims(c, fmt.Sprint("RequestBody:", string(body)))
-
- c.Request.Body = io.NopCloser(bytes.NewBuffer(body))
- c.Next()
- }
- func (common *Common) Page(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()
- }
|