From b4e27b88f5959255ec9323a90f9abb8a356ec60f Mon Sep 17 00:00:00 2001 From: "zcool321@sina.com" <1234qwer> Date: Sat, 14 Sep 2019 20:32:16 +0800 Subject: [PATCH] gtoken resp Unauthorized --- gtoken/gtoken.go | 10 +++++----- gtoken/gtoken_cache.go | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/gtoken/gtoken.go b/gtoken/gtoken.go index 00b4c75..f2910fe 100644 --- a/gtoken/gtoken.go +++ b/gtoken/gtoken.go @@ -234,10 +234,10 @@ func (m *GfToken) getRequestToken(r *ghttp.Request) resp.Resp { parts := strings.SplitN(authHeader, " ", 2) if !(len(parts) == 2 && parts[0] == "Bearer") { glog.Warning("[GToken]authHeader:" + authHeader + " get token key fail") - return resp.Fail("get token key fail") + return resp.Unauthorized("get token key fail", "") } else if parts[1] == "" { glog.Warning("[GToken]authHeader:" + authHeader + " get token fail") - return resp.Fail("get token fail") + return resp.Unauthorized("get token fail", "") } return resp.Succ(parts[1]) @@ -245,7 +245,7 @@ func (m *GfToken) getRequestToken(r *ghttp.Request) resp.Resp { authHeader = r.GetPostString("token") if authHeader == "" { - return resp.Fail("query token fail") + return resp.Unauthorized("query token fail", "") } return resp.Succ(authHeader) @@ -278,7 +278,7 @@ func (m *GfToken) genToken(userKey string, data interface{}) resp.Resp { // validToken 验证Token func (m *GfToken) validToken(token string) resp.Resp { if token == "" { - return resp.Fail("valid token empty") + return resp.Unauthorized("valid token empty", "") } decryptToken := m.DecryptToken(token) @@ -298,7 +298,7 @@ func (m *GfToken) validToken(token string) resp.Resp { if uuid != userCache["uuid"] { glog.Error("[GToken]user auth error, decryptToken:" + decryptToken.Json() + " cacheValue:" + gconv.String(userCache)) - return resp.Fail("user auth error") + return resp.Unauthorized("user auth error", "") } nowTime := gtime.Now().Millisecond() diff --git a/gtoken/gtoken_cache.go b/gtoken/gtoken_cache.go index 1212dfe..d17f970 100644 --- a/gtoken/gtoken_cache.go +++ b/gtoken/gtoken_cache.go @@ -39,7 +39,7 @@ func (m *GfToken) getCache(cacheKey string) resp.Resp { case CacheModeCache: userCacheValue := gcache.Get(cacheKey) if userCacheValue == nil { - return resp.Fail("login timeout or not login") + return resp.Unauthorized("login timeout or not login", "") } userCache = gconv.Map(userCacheValue) case CacheModeRedis: @@ -49,7 +49,7 @@ func (m *GfToken) getCache(cacheKey string) resp.Resp { return resp.Error("cache get error") } if userCacheJson == nil { - return resp.Fail("login timeout or not login") + return resp.Unauthorized("login timeout or not login", "") } err = gjson.DecodeTo(userCacheJson, &userCache)