gin.go 894 B

123456789101112131415161718192021222324252627282930313233343536
  1. package utils
  2. import "github.com/gin-gonic/gin"
  3. // SetBridgeLogListByClaims
  4. // @Description: 设置上下文中bridge日志
  5. // @author: Roc
  6. // @datetime 2024-10-31 10:55:15
  7. // @param c *gin.Context
  8. // @param logStr string
  9. func SetBridgeLogListByClaims(c *gin.Context, logStr string) {
  10. bridgeLogList := GetBridgeLogListByClaims(c)
  11. bridgeLogList = append(bridgeLogList, logStr)
  12. c.Set("bridge_log", bridgeLogList)
  13. return
  14. }
  15. // GetBridgeLogListByClaims
  16. // @Description: 从Claims中获取当前日志
  17. // @author: Roc
  18. // @datetime 2024-10-31 10:35:04
  19. // @param c *gin.Context
  20. // @return bridgeLogList []string
  21. func GetBridgeLogListByClaims(c *gin.Context) (bridgeLogList []string) {
  22. //获取jwt数据失败
  23. claims, exists := c.Get("bridge_log")
  24. // 如果不存在,那么就是空切片
  25. if !exists {
  26. bridgeLogList = []string{}
  27. return
  28. }
  29. bridgeLogList = claims.([]string)
  30. return
  31. }