未验证 提交 ef4c8a77 编写于 作者: Q qk winter 提交者: GitHub

Update clamis.go (#1450)

添加了GetUserName方法
上级 eb86bc53
......@@ -72,3 +72,17 @@ func GetUserInfo(c *gin.Context) *systemReq.CustomClaims {
return waitUse
}
}
// GetUserName 从Gin的Context中获取从jwt解析出来的用户名
func GetUserName(c *gin.Context) string {
if claims, exists := c.Get("claims"); !exists {
if cl, err := GetClaims(c); err != nil {
return ""
} else {
return cl.Username
}
} else {
waitUse := claims.(*systemReq.CustomClaims)
return waitUse.Username
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册