Refine the base bean.

This commit is contained in:
zicla 2019-04-28 01:29:13 +08:00
parent aaf7578290
commit e043b6b8d7
16 changed files with 36 additions and 36 deletions

View File

@ -3,7 +3,7 @@ package core
/**
* 系统中的Bean接口即系统中单例模式
*/
type IBean interface {
type Bean interface {
//初始化方法
Init()
//系统清理方法

View File

@ -14,7 +14,7 @@ type Context interface {
GetDB() *gorm.DB
//获取一个Bean
GetBean(bean IBean) IBean
GetBean(bean Bean) Bean
//获取全局的Session缓存
GetSessionCache() *cache.Table

View File

@ -3,7 +3,7 @@ package core
import "net/http"
type IController interface {
IBean
Bean
//注册自己固定的路由。
RegisterRoutes() map[string]func(writer http.ResponseWriter, request *http.Request)
//处理一些特殊的路由。

View File

@ -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)

View File

@ -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 {

View File

@ -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)

View File

@ -3,7 +3,7 @@ package rest
import "github.com/eyebluecn/tank/code/tool/builder"
type BaseDao struct {
Bean
BaseBean
}
//根据一个sortMap获取到order字符串

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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()