51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package services
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/sys/configure"
|
|
"sync"
|
|
|
|
"go_dreamfactory/lego/base/rpcx"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
)
|
|
|
|
// 梦工厂基础服务对象
|
|
type ServiceBase struct {
|
|
rpcx.RPCXService
|
|
pools sync.Pool
|
|
}
|
|
|
|
// 初始化相关系统
|
|
func (this *ServiceBase) InitSys() {
|
|
this.RPCXService.InitSys()
|
|
//初始化配置中心系统 每个服务都会用到的就在这个初始化就好
|
|
if err := configure.OnInit(this.GetSettings().Sys["configure"]); err != nil {
|
|
panic(fmt.Sprintf("init sys.configure err: %s", err.Error()))
|
|
} else {
|
|
configure.Start()
|
|
log.Infof("init sys.configure success!")
|
|
}
|
|
}
|
|
|
|
func (this *ServiceBase) Init(service core.IService) (err error) {
|
|
this.pools = sync.Pool{
|
|
New: func() interface{} {
|
|
s := comm.NewUserSessionByPools(this)
|
|
return s
|
|
},
|
|
}
|
|
err = this.RPCXService.Init(service)
|
|
return
|
|
}
|
|
|
|
func (this *ServiceBase) GetUserSession() (session comm.IUserSession) {
|
|
session = this.pools.Get().(comm.IUserSession)
|
|
return
|
|
}
|
|
|
|
func (this *ServiceBase) PutUserSession(session comm.IUserSession) {
|
|
this.pools.Put(session)
|
|
}
|