feat: client 增删改查

This commit is contained in:
Blizzard
2025-05-08 23:03:00 +08:00
parent 75e9157e5e
commit ab51ba91bc
41 changed files with 1093 additions and 57 deletions
+13
View File
@@ -78,6 +78,19 @@ func GetToken(c *gin.Context) string {
return token
}
// ClearToken 清除Cookie中的token
func ClearToken(c *gin.Context) {
host, _, err := net.SplitHostPort(c.Request.Host)
if err != nil {
host = c.Request.Host
}
if net.ParseIP(host) != nil {
c.SetCookie("x-token", "", -1, "/", "", false, false)
} else {
c.SetCookie("x-token", "", -1, "/", host, false, false)
}
}
// GetUserInfo 从 gin.Context 中获取用户信息,并返回 CustomClaims 类型的指针。
// 该函数首先尝试从上下文中获取已存在的 claims,如果不存在,则调用 GetClaims 函数获取 claims。
// 如果获取 claims 失败,则返回 nil。