123456789101112131415161718192021222324252627282930313233343536373839 |
- package utils
- import "github.com/gin-gonic/gin"
- // ContextLogName 上下文日志的名称
- const ContextLogName = `context_custom_log`
- // SetContextLogListByClaims
- // @Description: 设置上下文中日志
- // @author: Roc
- // @datetime 2024-10-31 10:55:15
- // @param c *gin.Context
- // @param logStr string
- func SetContextLogListByClaims(c *gin.Context, logStr string) {
- bridgeLogList := GetContextLogListByClaims(c)
- bridgeLogList = append(bridgeLogList, logStr)
- c.Set(ContextLogName, bridgeLogList)
- return
- }
- // GetContextLogListByClaims
- // @Description: 从Claims中获取当前日志
- // @author: Roc
- // @datetime 2024-10-31 10:35:04
- // @param c *gin.Context
- // @return bridgeLogList []string
- func GetContextLogListByClaims(c *gin.Context) (bridgeLogList []string) {
- //获取jwt数据失败
- claims, exists := c.Get(ContextLogName)
- // 如果不存在,那么就是空切片
- if !exists {
- bridgeLogList = []string{}
- return
- }
- bridgeLogList = claims.([]string)
- return
- }
|