Ready to refine the context and router bean.
This commit is contained in:
@ -8,13 +8,6 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type IController interface {
|
||||
IBean
|
||||
//注册自己固定的路由。
|
||||
RegisterRoutes() map[string]func(writer http.ResponseWriter, request *http.Request)
|
||||
//处理一些特殊的路由。
|
||||
HandleRoutes(writer http.ResponseWriter, request *http.Request) (func(writer http.ResponseWriter, request *http.Request), bool)
|
||||
}
|
||||
type BaseController struct {
|
||||
Bean
|
||||
userDao *UserDao
|
||||
|
@ -8,17 +8,6 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type IBean interface {
|
||||
//初始化方法
|
||||
Init()
|
||||
//系统清理方法
|
||||
Cleanup()
|
||||
//所有配置都加载完成后调用的方法,包括数据库加载完毕
|
||||
Bootstrap()
|
||||
//快速的Panic方法
|
||||
PanicError(err error)
|
||||
}
|
||||
|
||||
type Bean struct {
|
||||
logger core.Logger
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/eyebluecn/tank/code/config"
|
||||
"github.com/eyebluecn/tank/code/core"
|
||||
cache2 "github.com/eyebluecn/tank/code/tool/cache"
|
||||
"github.com/eyebluecn/tank/code/tool/cache"
|
||||
"github.com/jinzhu/gorm"
|
||||
"reflect"
|
||||
)
|
||||
@ -17,9 +17,9 @@ type Context struct {
|
||||
//数据库连接
|
||||
DB *gorm.DB
|
||||
//session缓存
|
||||
SessionCache *cache2.Table
|
||||
SessionCache *cache.Table
|
||||
//各类的Bean Map。这里面是包含ControllerMap中所有元素
|
||||
BeanMap map[string]IBean
|
||||
BeanMap map[string]core.IBean
|
||||
//只包含了Controller的map
|
||||
ControllerMap map[string]IController
|
||||
//处理所有路由请求
|
||||
@ -30,10 +30,10 @@ type Context struct {
|
||||
func (this *Context) Init() {
|
||||
|
||||
//创建一个用于存储session的缓存。
|
||||
this.SessionCache = cache2.NewTable()
|
||||
this.SessionCache = cache.NewTable()
|
||||
|
||||
//初始化Map
|
||||
this.BeanMap = make(map[string]IBean)
|
||||
this.BeanMap = make(map[string]core.IBean)
|
||||
this.ControllerMap = make(map[string]IController)
|
||||
|
||||
//注册各类Beans.在这个方法里面顺便把Controller装入ControllerMap中去。
|
||||
@ -74,12 +74,12 @@ func (this *Context) CloseDb() {
|
||||
}
|
||||
|
||||
//注册一个Bean
|
||||
func (this *Context) registerBean(bean IBean) {
|
||||
func (this *Context) registerBean(bean core.IBean) {
|
||||
|
||||
typeOf := reflect.TypeOf(bean)
|
||||
typeName := typeOf.String()
|
||||
|
||||
if element, ok := bean.(IBean); ok {
|
||||
if element, ok := bean.(core.IBean); ok {
|
||||
|
||||
err := fmt.Sprintf("【%s】已经被注册了,跳过。", typeName)
|
||||
if _, ok := this.BeanMap[typeName]; ok {
|
||||
@ -157,7 +157,7 @@ func (this *Context) registerBeans() {
|
||||
}
|
||||
|
||||
//从Map中获取某个Bean.
|
||||
func (this *Context) GetBean(bean IBean) IBean {
|
||||
func (this *Context) GetBean(bean core.IBean) core.IBean {
|
||||
|
||||
typeOf := reflect.TypeOf(bean)
|
||||
typeName := typeOf.String()
|
||||
|
Reference in New Issue
Block a user