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