Refine the context and Try to fix the nil issue.

This commit is contained in:
zicla
2019-04-28 00:36:21 +08:00
parent fa28bbb83f
commit 3ffc4090e0
34 changed files with 246 additions and 167 deletions

View File

@ -2,6 +2,7 @@ package rest
import (
"github.com/eyebluecn/tank/code/config"
"github.com/eyebluecn/tank/code/core"
"github.com/eyebluecn/tank/code/tool/cache"
"github.com/eyebluecn/tank/code/tool/result"
"net/http"
@ -23,12 +24,12 @@ func (this *UserService) Init() {
this.Bean.Init()
//手动装填本实例的Bean. 这里必须要用中间变量方可。
b := CONTEXT.GetBean(this.userDao)
b := core.CONTEXT.GetBean(this.userDao)
if b, ok := b.(*UserDao); ok {
this.userDao = b
}
b = CONTEXT.GetBean(this.sessionDao)
b = core.CONTEXT.GetBean(this.sessionDao)
if b, ok := b.(*SessionDao); ok {
this.sessionDao = b
}
@ -84,7 +85,7 @@ func (this *UserService) preHandle(writer http.ResponseWriter, request *http.Req
sessionId := sessionCookie.Value
//去缓存中捞取
cacheItem, err := CONTEXT.SessionCache.Value(sessionId)
cacheItem, err := core.CONTEXT.GetSessionCache().Value(sessionId)
if err != nil {
this.logger.Error("获取缓存时出错了" + err.Error())
}
@ -100,7 +101,7 @@ func (this *UserService) preHandle(writer http.ResponseWriter, request *http.Req
user := this.userDao.FindByUuid(session.UserUuid)
if user != nil {
//将用户装填进缓存中
CONTEXT.SessionCache.Add(sessionCookie.Value, duration, user)
core.CONTEXT.GetSessionCache().Add(sessionCookie.Value, duration, user)
} else {
this.logger.Error("没有找到对应的user " + session.UserUuid)
}