Keep refine the structure.

This commit is contained in:
zicla
2019-04-26 02:38:53 +08:00
parent b3c52ea50e
commit 8edc30babc
11 changed files with 56 additions and 50 deletions

View File

@ -4,8 +4,9 @@ import (
"fmt"
"github.com/jinzhu/gorm"
"reflect"
"tank/rest/cache"
"tank/rest/config"
"tank/rest/tool"
"tank/rest/logger"
)
//全局唯一的上下文(在main函数中初始化)
@ -16,7 +17,7 @@ type Context struct {
//数据库连接
DB *gorm.DB
//session缓存
SessionCache *tool.CacheTable
SessionCache *cache.CacheTable
//各类的Bean Map。这里面是包含ControllerMap中所有元素
BeanMap map[string]IBean
//只包含了Controller的map
@ -29,7 +30,7 @@ type Context struct {
func (this *Context) Init() {
//创建一个用于存储session的缓存。
this.SessionCache = tool.NewCacheTable()
this.SessionCache = cache.NewCacheTable()
//初始化Map
this.BeanMap = make(map[string]IBean)
@ -55,7 +56,7 @@ func (this *Context) OpenDb() {
this.DB, err = gorm.Open("mysql", config.CONFIG.MysqlUrl)
if err != nil {
tool.LOGGER.Panic("failed to connect mysql database")
logger.LOGGER.Panic("failed to connect mysql database")
}
//是否打开sql日志(在调试阶段可以打开以方便查看执行的SQL)
@ -82,7 +83,7 @@ func (this *Context) registerBean(bean IBean) {
err := fmt.Sprintf("【%s】已经被注册了跳过。", typeName)
if _, ok := this.BeanMap[typeName]; ok {
tool.LOGGER.Error(fmt.Sprintf(err))
logger.LOGGER.Error(fmt.Sprintf(err))
} else {
this.BeanMap[typeName] = element
@ -94,7 +95,7 @@ func (this *Context) registerBean(bean IBean) {
}
} else {
tool.LOGGER.Panic("注册的【%s】不是Bean类型。", typeName)
logger.LOGGER.Panic("注册的【%s】不是Bean类型。", typeName)
}
}
@ -164,7 +165,7 @@ func (this *Context) GetBean(bean IBean) IBean {
if val, ok := this.BeanMap[typeName]; ok {
return val
} else {
tool.LOGGER.Panic("【%s】没有注册。", typeName)
logger.LOGGER.Panic("【%s】没有注册。", typeName)
return nil
}
}