diff --git a/code/core/bean.go b/code/core/bean.go index cfd4de4..a34301d 100644 --- a/code/core/bean.go +++ b/code/core/bean.go @@ -3,7 +3,7 @@ package core /** * 系统中的Bean接口,即系统中单例模式 */ -type IBean interface { +type Bean interface { //初始化方法 Init() //系统清理方法 diff --git a/code/core/context.go b/code/core/context.go index dd4cf80..162d561 100644 --- a/code/core/context.go +++ b/code/core/context.go @@ -14,7 +14,7 @@ type Context interface { GetDB() *gorm.DB //获取一个Bean - GetBean(bean IBean) IBean + GetBean(bean Bean) Bean //获取全局的Session缓存 GetSessionCache() *cache.Table diff --git a/code/core/controller.go b/code/core/controller.go index d3c18d1..27843aa 100644 --- a/code/core/controller.go +++ b/code/core/controller.go @@ -3,7 +3,7 @@ package core import "net/http" type IController interface { - IBean + Bean //注册自己固定的路由。 RegisterRoutes() map[string]func(writer http.ResponseWriter, request *http.Request) //处理一些特殊的路由。 diff --git a/code/rest/alien_service.go b/code/rest/alien_service.go index 673fdab..d83d265 100644 --- a/code/rest/alien_service.go +++ b/code/rest/alien_service.go @@ -11,7 +11,7 @@ import ( //@Service type AlienService struct { - Bean + BaseBean matterDao *MatterDao matterService *MatterService userDao *UserDao @@ -23,7 +23,7 @@ type AlienService struct { //初始化方法 func (this *AlienService) Init() { - this.Bean.Init() + this.BaseBean.Init() //手动装填本实例的Bean. 这里必须要用中间变量方可。 b := core.CONTEXT.GetBean(this.matterDao) diff --git a/code/rest/bean.go b/code/rest/base_bean.go similarity index 79% rename from code/rest/bean.go rename to code/rest/base_bean.go index 3e3c253..040222b 100644 --- a/code/rest/bean.go +++ b/code/rest/base_bean.go @@ -7,30 +7,30 @@ import ( "net/http" ) -type Bean struct { +type BaseBean struct { logger core.Logger } -func (this *Bean) Init() { +func (this *BaseBean) Init() { this.logger = core.LOGGER } -func (this *Bean) Bootstrap() { +func (this *BaseBean) Bootstrap() { } //系统大清理,一般时产品即将上线时,清除脏数据,只执行一次。 -func (this *Bean) Cleanup() { +func (this *BaseBean) Cleanup() { } //处理错误的统一方法 可以省去if err!=nil 这段代码 -func (this *Bean) PanicError(err error) { +func (this *BaseBean) PanicError(err error) { util.PanicError(err) } //能找到一个user就找到一个 -func (this *Bean) findUser(writer http.ResponseWriter, request *http.Request) *User { +func (this *BaseBean) findUser(writer http.ResponseWriter, request *http.Request) *User { //验证用户是否已经登录。 //登录身份有效期以数据库中记录的为准 @@ -62,7 +62,7 @@ func (this *Bean) findUser(writer http.ResponseWriter, request *http.Request) *U } //获取当前登录的用户,找不到就返回登录错误 -func (this *Bean) checkUser(writer http.ResponseWriter, request *http.Request) *User { +func (this *BaseBean) checkUser(writer http.ResponseWriter, request *http.Request) *User { if this.findUser(writer, request) == nil { panic(result.ConstWebResult(result.CODE_WRAPPER_LOGIN)) } else { diff --git a/code/rest/base_controller.go b/code/rest/base_controller.go index 08bc979..6180d03 100644 --- a/code/rest/base_controller.go +++ b/code/rest/base_controller.go @@ -10,14 +10,14 @@ import ( ) type BaseController struct { - Bean + BaseBean userDao *UserDao sessionDao *SessionDao } func (this *BaseController) Init() { - this.Bean.Init() + this.BaseBean.Init() //手动装填本实例的Bean. b := core.CONTEXT.GetBean(this.userDao) diff --git a/code/rest/base_dao.go b/code/rest/base_dao.go index 4b2b3e7..9c90e0d 100644 --- a/code/rest/base_dao.go +++ b/code/rest/base_dao.go @@ -3,7 +3,7 @@ package rest import "github.com/eyebluecn/tank/code/tool/builder" type BaseDao struct { - Bean + BaseBean } //根据一个sortMap,获取到order字符串 diff --git a/code/rest/dashboard_service.go b/code/rest/dashboard_service.go index e5ddb44..406e6b2 100644 --- a/code/rest/dashboard_service.go +++ b/code/rest/dashboard_service.go @@ -9,7 +9,7 @@ import ( //@Service type DashboardService struct { - Bean + BaseBean dashboardDao *DashboardDao footprintDao *FootprintDao matterDao *MatterDao @@ -19,7 +19,7 @@ type DashboardService struct { //初始化方法 func (this *DashboardService) Init() { - this.Bean.Init() + this.BaseBean.Init() //手动装填本实例的Bean. 这里必须要用中间变量方可。 b := core.CONTEXT.GetBean(this.dashboardDao) diff --git a/code/rest/dav_service.go b/code/rest/dav_service.go index 003f331..37c1066 100644 --- a/code/rest/dav_service.go +++ b/code/rest/dav_service.go @@ -23,14 +23,14 @@ import ( */ //@Service type DavService struct { - Bean + BaseBean matterDao *MatterDao matterService *MatterService } //初始化方法 func (this *DavService) Init() { - this.Bean.Init() + this.BaseBean.Init() //手动装填本实例的Bean. 这里必须要用中间变量方可。 b := core.CONTEXT.GetBean(this.matterDao) diff --git a/code/rest/footprint_service.go b/code/rest/footprint_service.go index 9c6785e..3043488 100644 --- a/code/rest/footprint_service.go +++ b/code/rest/footprint_service.go @@ -12,14 +12,14 @@ import ( //@Service type FootprintService struct { - Bean + BaseBean footprintDao *FootprintDao userDao *UserDao } //初始化方法 func (this *FootprintService) Init() { - this.Bean.Init() + this.BaseBean.Init() //手动装填本实例的Bean. 这里必须要用中间变量方可。 b := core.CONTEXT.GetBean(this.footprintDao) diff --git a/code/rest/image_cache_service.go b/code/rest/image_cache_service.go index 31eeff8..1bdc0a3 100644 --- a/code/rest/image_cache_service.go +++ b/code/rest/image_cache_service.go @@ -15,7 +15,7 @@ import ( //@Service type ImageCacheService struct { - Bean + BaseBean imageCacheDao *ImageCacheDao userDao *UserDao matterDao *MatterDao @@ -23,7 +23,7 @@ type ImageCacheService struct { //初始化方法 func (this *ImageCacheService) Init() { - this.Bean.Init() + this.BaseBean.Init() //手动装填本实例的Bean. 这里必须要用中间变量方可。 b := core.CONTEXT.GetBean(this.imageCacheDao) diff --git a/code/rest/matter_service.go b/code/rest/matter_service.go index 899449a..f1b228a 100644 --- a/code/rest/matter_service.go +++ b/code/rest/matter_service.go @@ -18,7 +18,7 @@ import ( */ //@Service type MatterService struct { - Bean + BaseBean matterDao *MatterDao userDao *UserDao userService *UserService @@ -28,7 +28,7 @@ type MatterService struct { //初始化方法 func (this *MatterService) Init() { - this.Bean.Init() + this.BaseBean.Init() //手动装填本实例的Bean. 这里必须要用中间变量方可。 b := core.CONTEXT.GetBean(this.matterDao) diff --git a/code/rest/preference_service.go b/code/rest/preference_service.go index 8d0e0c7..6679ef3 100644 --- a/code/rest/preference_service.go +++ b/code/rest/preference_service.go @@ -4,14 +4,14 @@ import "github.com/eyebluecn/tank/code/core" //@Service type PreferenceService struct { - Bean + BaseBean preferenceDao *PreferenceDao preference *Preference } //初始化方法 func (this *PreferenceService) Init() { - this.Bean.Init() + this.BaseBean.Init() //手动装填本实例的Bean. 这里必须要用中间变量方可。 b := core.CONTEXT.GetBean(this.preferenceDao) diff --git a/code/rest/session_service.go b/code/rest/session_service.go index 3b1b85c..58e5e16 100644 --- a/code/rest/session_service.go +++ b/code/rest/session_service.go @@ -4,14 +4,14 @@ import "github.com/eyebluecn/tank/code/core" //@Service type SessionService struct { - Bean + BaseBean userDao *UserDao sessionDao *SessionDao } //初始化方法 func (this *SessionService) Init() { - this.Bean.Init() + this.BaseBean.Init() //手动装填本实例的Bean. 这里必须要用中间变量方可。 b := core.CONTEXT.GetBean(this.userDao) diff --git a/code/rest/user_service.go b/code/rest/user_service.go index e8dc4e6..8aa7719 100644 --- a/code/rest/user_service.go +++ b/code/rest/user_service.go @@ -10,7 +10,7 @@ import ( //@Service type UserService struct { - Bean + BaseBean userDao *UserDao sessionDao *SessionDao @@ -20,7 +20,7 @@ type UserService struct { //初始化方法 func (this *UserService) Init() { - this.Bean.Init() + this.BaseBean.Init() //手动装填本实例的Bean. 这里必须要用中间变量方可。 b := core.CONTEXT.GetBean(this.userDao) diff --git a/code/support/tank_context.go b/code/support/tank_context.go index 2a44193..841c6cb 100644 --- a/code/support/tank_context.go +++ b/code/support/tank_context.go @@ -18,7 +18,7 @@ type TankContext struct { //session缓存 SessionCache *cache.Table //各类的Bean Map。这里面是包含ControllerMap中所有元素 - BeanMap map[string]core.IBean + BeanMap map[string]core.Bean //只包含了Controller的map ControllerMap map[string]core.IController //处理所有路由请求 @@ -32,7 +32,7 @@ func (this *TankContext) Init() { this.SessionCache = cache.NewTable() //初始化Map - this.BeanMap = make(map[string]core.IBean) + this.BeanMap = make(map[string]core.Bean) this.ControllerMap = make(map[string]core.IController) //注册各类Beans.在这个方法里面顺便把Controller装入ControllerMap中去。 @@ -97,12 +97,12 @@ func (this *TankContext) CloseDb() { } //注册一个Bean -func (this *TankContext) registerBean(bean core.IBean) { +func (this *TankContext) registerBean(bean core.Bean) { typeOf := reflect.TypeOf(bean) typeName := typeOf.String() - if element, ok := bean.(core.IBean); ok { + if element, ok := bean.(core.Bean); ok { err := fmt.Sprintf("【%s】已经被注册了,跳过。", typeName) if _, ok := this.BeanMap[typeName]; ok { @@ -180,7 +180,7 @@ func (this *TankContext) registerBeans() { } //从Map中获取某个Bean. -func (this *TankContext) GetBean(bean core.IBean) core.IBean { +func (this *TankContext) GetBean(bean core.Bean) core.Bean { typeOf := reflect.TypeOf(bean) typeName := typeOf.String()