common.go 947 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package middleware
  2. import (
  3. "bytes"
  4. "eta_gn/eta_bridge/utils"
  5. "fmt"
  6. "github.com/gin-gonic/gin"
  7. "io"
  8. "net/http"
  9. "strconv"
  10. )
  11. type Common struct{}
  12. func (common *Common) Page(c *gin.Context) {
  13. var currPage, pageSize int
  14. reqPage := c.DefaultQuery("curr_page", "0")
  15. currPage, _ = strconv.Atoi(reqPage)
  16. if currPage <= 0 {
  17. currPage = 1
  18. }
  19. reqPageSize := c.DefaultQuery("page_size", "0")
  20. pageSize, _ = strconv.Atoi(reqPageSize)
  21. if pageSize <= 0 {
  22. pageSize = 20
  23. }
  24. c.Set("curr_page", currPage)
  25. c.Set("page_size", pageSize)
  26. c.Next()
  27. }
  28. func (common *Common) RequestLog(c *gin.Context) {
  29. body, err := io.ReadAll(c.Request.Body)
  30. if err != nil {
  31. c.AbortWithStatus(http.StatusInternalServerError)
  32. return
  33. }
  34. utils.SetBridgeLogListByClaims(c, fmt.Sprint("Url:", c.Request.RequestURI))
  35. utils.SetBridgeLogListByClaims(c, fmt.Sprint("RequestBody:", string(body)))
  36. c.Request.Body = io.NopCloser(bytes.NewBuffer(body))
  37. c.Next()
  38. }