zhangqian
2023-10-13 4a23356a5840b624c81dda44b0028ed8fc3656cc
utils/clamis.go
@@ -22,30 +22,18 @@
   return claims, err
}
// GetUserID 从Gin的Context中获取从jwt解析出来的用户ID
func GetUserID(c *gin.Context) string {
   if claims, exists := c.Get("claims"); !exists {
      if cl, err := GetClaims(c); err != nil {
         return ""
      } else {
         return cl.UserId
      }
   } else {
func GetUserID(c *gin.Context) int {
   if claims, exists := c.Get("claims"); exists {
      waitUse := claims.(*request.CustomClaims)
      return waitUse.UserId
      return waitUse.CrmUserId
   }
   return 0
}
// GetUserInfo 从Gin的Context中获取从jwt解析出来的用户信息
func GetUserInfo(c *gin.Context) *request.CustomClaims {
   if claims, exists := c.Get("claims"); !exists {
      if cl, err := GetClaims(c); err != nil {
         return nil
      } else {
         return cl
      }
   } else {
   if claims, exists := c.Get("claims"); exists {
      waitUse := claims.(*request.CustomClaims)
      return waitUse
   }
   return nil
}