Documentation
¶
Index ¶
- Variables
- func CheckModel(md IDataBaseModel) error
- func DBResolveModel(md IDataBaseModel) (result map[string]reflect.Value)
- func GetKeyNameResolve(keyname string) (table string, pid, uid uint64)
- func GetRowKeyName(data IDataBaseModel) string
- func GetRowKeyNameByPID(tname string, pid uint64) string
- func GetRowKeyNameByUID(tname string, pid, uid uint64) string
- func MsgDBUpUserDataReq(pid, space, sid uint64, mds ...IDataBaseModel)
- func MsgDBUpUserDatasReq(pid, space, sid uint64, args *DataArgs) msgdef.IMsg
- func NewEntityUtilDBData(pid uint64) (result *dbsessionUtil)
- func PackMsgData(v reflect.Value) (result *protomsg.FieldData)
- func PostDBPlayer(pid uint64, reqMsg msgdef.IMsg)
- func PostDBServer(space, srvID uint64, reqMsg msgdef.IMsg)
- func PostOther(pid, space, srvid uint64, reqMsg msgdef.IMsg)
- func SetDataModel(md IDataBaseModel, msgdata *protomsg.TableData)
- func SetDataModel2(md IDataBaseModel, msgdata *protomsg.TableData, args *DataArgs)
- func SetDataModel2ByMsg(md IDataBaseModel, msg *protomsg.DBDataModel, args *DataArgs)
- func SetDataModelByMsg(md IDataBaseModel, msg *protomsg.DBDataModel)
- func UnPackMsgDataToField(f reflect.Value, msgdata *protomsg.FieldData)
- type DBPlayer
- func (this *DBPlayer) AddOtherModel(v IServiceModel)
- func (this *DBPlayer) AddServiceModel(v IServiceModel)
- func (this *DBPlayer) AllDataSync()
- func (this *DBPlayer) AllLoaded()
- func (this *DBPlayer) DelayLoads()
- func (this *DBPlayer) GetArgs() *DataArgs
- func (this *DBPlayer) Init(tmpli map[string]IDataBaseModel) (ok bool)
- func (this *DBPlayer) Loop()
- func (this *DBPlayer) PopBackFunc(key uint64) GetData
- func (this *DBPlayer) Save()
- func (this *DBPlayer) SetBackFunc(key uint64, f GetData)
- func (this *DBPlayer) SetOnLoaded(f func())
- type DataArgs
- func (args *DataArgs) Clear()
- func (args *DataArgs) Delete(md IDataBaseModel)
- func (args *DataArgs) GetDirtyData() map[string]IDataBaseModel
- func (args *DataArgs) GetModelByKeyName(keyname string) IDataBaseModel
- func (args *DataArgs) GetMsgByAllData(f func(v IDataBaseModel, db *protomsg.DBDataModel) (issync bool)) (result *protomsg.DBUpUserDatasReq)
- func (args *DataArgs) GetMsgByForFunc(f func(v IDataBaseModel, db *protomsg.DBDataModel) (issave bool)) (result *protomsg.DBUpUserDatasReq)
- func (args *DataArgs) GetPID() uint64
- func (args *DataArgs) LoadData(md IDataBaseModel)
- func (args *DataArgs) RevokeDelete(md IDataBaseModel)
- func (args *DataArgs) SetUpdate(md IDataBaseModel, k string, v interface{}) error
- func (args *DataArgs) Update(md IDataBaseModel) error
- func (args *DataArgs) UpdateField(keyname, field string) error
- type DataUtil
- func (utilmd *DataUtil) DelDataArray(mli []*protomsg.DBDataModel)
- func (utilmd *DataUtil) DelDatas(tname string, keynames []string)
- func (utilmd *DataUtil) GetFieldKey(id uint64, modname string) (key string)
- func (utilmd *DataUtil) GetKeySplitToFieldName(key string) (id uint64, field string)
- func (utilmd *DataUtil) Key(tname string) string
- func (utilmd *DataUtil) RowsSingleDels(table string, uid uint64, li map[string]reflect.Value)
- func (utilmd *DataUtil) RowsSingleGet(table string) (result map[string][]byte, err error)
- func (utilmd *DataUtil) RowsSingleSet(table string, pid, uid uint64, li map[string]reflect.Value)
- func (utilmd *DataUtil) SetDatas(pmsgs []*protomsg.DBDataModel) error
- type DelayLoadMgr
- type GetData
- type GetMsgForFunc
- type IDataBaseModel
- type IDeleted
- type IPlayer
- type IPlayerSubBase
- type IReal
- type IRedisValuer
- type IServiceModel
- type IServicePlayer
- type ISetArgs
- type Iprotomsg
- type MapModel
- func (this *MapModel) GetID() uint64
- func (this *MapModel) GetIsPartial() bool
- func (this *MapModel) GetPlayerID() uint64
- func (this *MapModel) IsDeleted() bool
- func (this *MapModel) KeyName() string
- func (this *MapModel) Marshal() ([]byte, error)
- func (this *MapModel) RevokeDelete()
- func (this *MapModel) SetData(k string, v reflect.Value)
- func (this *MapModel) SetDelete()
- func (this *MapModel) SetID(id uint64)
- func (this *MapModel) SetPlayerID(v uint64)
- func (this *MapModel) TableName() string
- func (this *MapModel) Unmarshal(data []byte) error
- type ModuleBase
- func (this *ModuleBase) AllDataSyncClient()
- func (this *ModuleBase) DelRedisDatas(li map[string]IDataBaseModel, dbli []*protomsg.DBDataModel)
- func (this *ModuleBase) GetDataArgs() *DataArgs
- func (this *ModuleBase) GetIsLoaded() bool
- func (this *ModuleBase) GetRedisTableDataAllDoMD(tnames []string) (result map[string][]IDataBaseModel, err error)
- func (this *ModuleBase) GetRedisTableDataDoMD(tname string) (result []IDataBaseModel, err error)
- func (this *ModuleBase) GetServiceName() string
- func (this *ModuleBase) GetTableNames() []string
- func (this *ModuleBase) IsDelayLoad() bool
- func (this *ModuleBase) IsSingleTable() (result bool, limit int32)
- func (this *ModuleBase) LoadDB(lis map[string][]IDataBaseModel)
- func (this *ModuleBase) LoadData(lis map[string][]IDataBaseModel)
- func (this *ModuleBase) OtherData(*protomsg.DBUpUserDatasReq)
- func (this *ModuleBase) OtherDataReqSrv() []*protomsg.DBDataModel
- func (this *ModuleBase) SaveRedis(li map[string]IDataBaseModel, msg *protomsg.DBUpUserDatasReq)
- func (this *ModuleBase) SaveRedisDatas(li map[string]IDataBaseModel, dbli []*protomsg.DBDataModel)
- func (this *ModuleBase) SetDataArgs(args *DataArgs)
- func (this *ModuleBase) SetRedisTableDataDoByte(data *MapModel) (err error)
- func (this *ModuleBase) SyncData()
- type NewTableFunc
- type OtherSrvMsgProc
- type PlayerBase
- type PlayerSubBase
- type TypeMgr
- func (mgr *TypeMgr) GetModelByKeyName(keyname string) IDataBaseModel
- func (mgr *TypeMgr) GetPlayerMainTableName() string
- func (mgr *TypeMgr) GetTableList() map[string]NewTableFunc
- func (mgr *TypeMgr) GetTableNames() []string
- func (mgr *TypeMgr) GetTypeByTname(tname string) IDataBaseModel
- func (mgr TypeMgr) GetValueByTname(tname string) reflect.Value
- func (mgr *TypeMgr) RegisterType(f NewTableFunc)
- type ValueMD
Constants ¶
This section is empty.
Variables ¶
var ( ErrPlayer = fmt.Errorf(" PlayerID == 0") ErrID = fmt.Errorf(" ID == 0") ErrPartial = fmt.Errorf(" SetUpdate fail GetIsPartial() fail") ErrAllMD = fmt.Errorf(" SetUpdate fail is All data") //这个数据做了全量更新了 ErrNoData = fmt.Errorf(" Load redis no data") //获取redis数据,没有对应的数据 ErrNoLoadData = common.NewError(" Load data not exist.keyname:%s") //不存在缓存数据 )
var ErrTokenVerify = errors.New("token error")
Functions ¶
func DBResolveModel ¶
func DBResolveModel(md IDataBaseModel) (result map[string]reflect.Value)
把数据分解成字段数据
func GetKeyNameResolve ¶
分解KeyName
func MsgDBUpUserDataReq ¶
func MsgDBUpUserDataReq(pid, space, sid uint64, mds ...IDataBaseModel)
向DB服发送表数据更新
func MsgDBUpUserDatasReq ¶
向DB发送请求user数据请求
func NewEntityUtilDBData ¶
func NewEntityUtilDBData(pid uint64) (result *dbsessionUtil)
SessionUtil 获得Session表的工具类
func SetDataModel2 ¶
func SetDataModel2(md IDataBaseModel, msgdata *protomsg.TableData, args *DataArgs)
设置数据到差量中去 包含标脏
func SetDataModel2ByMsg ¶
func SetDataModel2ByMsg(md IDataBaseModel, msg *protomsg.DBDataModel, args *DataArgs)
从消息中设置数据差量 包含标脏
func SetDataModelByMsg ¶
func SetDataModelByMsg(md IDataBaseModel, msg *protomsg.DBDataModel)
从消息中设置数据差量
Types ¶
type DBPlayer ¶
type DBPlayer struct { //是否加载同步模块完成 IsLoadAllSync bool //是否加载所有模块 IsLoadAll bool //模块列表 ModelList map[string]IServiceModel //模块的加载顺序列表 LoadLi []IServiceModel //延时加载的模块 DelayLoadLi []IServiceModel //与他服系统通信的 模块列表 OtherLoadLi []IServiceModel // contains filtered or unexported fields }
这个对象是放在每个玩家身上的,可以用来做为管理系统使用 按照设计所有对象都应该放在这里管理 他们都实现了IServiceModel接口
func NewDBPlayer ¶
func NewDBPlayer(player IServicePlayer, sid uint64, f func()) *DBPlayer
func (*DBPlayer) AddOtherModel ¶
func (this *DBPlayer) AddOtherModel(v IServiceModel)
添加模块进 他服通信 模块列表
func (*DBPlayer) AddServiceModel ¶
func (this *DBPlayer) AddServiceModel(v IServiceModel)
添加的时候,按加载的顺序进行添加
func (*DBPlayer) Init ¶
func (this *DBPlayer) Init(tmpli map[string]IDataBaseModel) (ok bool)
先加载试试,如果加载失败就走回调,如果加载完成就返回true
func (*DBPlayer) PopBackFunc ¶
获取回调方法,获取的时候会从集合里移除
func (*DBPlayer) SetBackFunc ¶
func (*DBPlayer) SetOnLoaded ¶
func (this *DBPlayer) SetOnLoaded(f func())
type DataArgs ¶
type DataArgs struct {
// contains filtered or unexported fields
}
func NewDataArgs ¶
func (*DataArgs) Delete ¶
func (args *DataArgs) Delete(md IDataBaseModel)
func (*DataArgs) GetDirtyData ¶
func (args *DataArgs) GetDirtyData() map[string]IDataBaseModel
获取脏数据
func (*DataArgs) GetModelByKeyName ¶
func (args *DataArgs) GetModelByKeyName(keyname string) IDataBaseModel
使用Keyname获取数据对象
func (*DataArgs) GetMsgByAllData ¶
func (args *DataArgs) GetMsgByAllData(f func(v IDataBaseModel, db *protomsg.DBDataModel) (issync bool)) (result *protomsg.DBUpUserDatasReq)
获取全量更新数据包
func (*DataArgs) GetMsgByForFunc ¶
func (args *DataArgs) GetMsgByForFunc(f func(v IDataBaseModel, db *protomsg.DBDataModel) (issave bool)) (result *protomsg.DBUpUserDatasReq)
返回发给DB服的消息,可以注入遍历时的函数
func (*DataArgs) SetUpdate ¶
func (args *DataArgs) SetUpdate(md IDataBaseModel, k string, v interface{}) error
设置脏字段,部分Field更新
func (*DataArgs) UpdateField ¶
新的使用字段名就可以更新数据的逻辑
type DataUtil ¶
type DataUtil struct {
// contains filtered or unexported fields
}
func (*DataUtil) DelDataArray ¶
func (utilmd *DataUtil) DelDataArray(mli []*protomsg.DBDataModel)
删除标记为需要删的数据行
func (*DataUtil) GetFieldKey ¶
获取字段Key
func (*DataUtil) GetKeySplitToFieldName ¶
获取字段名字和主键ID
func (*DataUtil) RowsSingleDels ¶
func (*DataUtil) RowsSingleGet ¶
多行数据:一个用户有多行,同时支持标脏字段的操作方法 以下的方法是针对一个用户多行数据的,每个字段都需要单独更新的时候,才使用的的逻辑
[多行数据]获取
func (*DataUtil) RowsSingleSet ¶
[多行数据]写入
type DelayLoadMgr ¶
type DelayLoadMgr struct { IServiceModel // contains filtered or unexported fields }
延时加载的处理器
func (*DelayLoadMgr) DelayLoad ¶
func (this *DelayLoadMgr) DelayLoad(tmpli map[string]IDataBaseModel) bool
收到消息回调
func (*DelayLoadMgr) SendDBLoadMsg ¶
func (this *DelayLoadMgr) SendDBLoadMsg(user *DBPlayer)
单独发本系统的数据请求
type GetMsgForFunc ¶
type GetMsgForFunc func(v IDataBaseModel, db *protomsg.DBDataModel) (issave bool)
用于ModuleBase在SyncData里对单个数据进行生成数据的回调函数 issave 为true表示需要保存在DB;
type IDataBaseModel ¶
type IDataBaseModel interface { IDeleted // KeyName 数据的唯一名字 KeyName() string // GetPlayerID 用户主键 GetPlayerID() uint64 // TableName 拿到表名 TableName() string // Marshal 序列化 Marshal() ([]byte, error) // Unmarshal 反序列化 Unmarshal(data []byte) error //是否支持部分更新 GetIsPartial() bool }
IDataBaseModel 可以被DB管理器管理的类需要实现的接口
type IPlayer ¶
type IPlayer interface { GetDBID() uint64 SetBackFunc(key uint64, f GetData) PopBackFunc(key uint64) GetData //获取回调方法,获取的时候会从集合里移除 }
Player接口
type IPlayerSubBase ¶
type IPlayerSubBase interface { IDataBaseModel //获取主键ID GetID() uint64 //设置主键ID SetID(id uint64) }
支持一表多行的数据,每一行都会有一个自己的ID
type IReal ¶
type IReal interface { IDataBaseModel GetMDReal() IDataBaseModel }
放在dataargs中的对象可能是最外面的对象 如果是最多面的对象,需要可以获取DB使用的对象 用与DBResolveModel分解字段的时候,使用
type IRedisValuer ¶
用与redis保存数据的接口
type IServiceModel ¶
type IServiceModel interface { //系统名字 GetServiceName() string //初始化 LoadDB(lis map[string][]IDataBaseModel) // //redis加载方式,如果加载成功就返回true // LoadRedis() bool //从redis获取数据 GetRedisTableDataAllDoMD(tnames []string) (result map[string][]IDataBaseModel, err error) //redis加载方式,如果加载成功就返回true LoadData(lis map[string][]IDataBaseModel) //需要的表名 GetTableNames() []string //是否加载过 GetIsLoaded() bool //他服逻辑-同步数据 OtherData(msg *protomsg.DBUpUserDatasReq) //同步数据到客户端;到redis;到dbserver SyncData() //全数据同步到客户端 AllDataSyncClient() //他服数据请求 OtherDataReqSrv() []*protomsg.DBDataModel //设置脏数据收集器 SetDataArgs(args *DataArgs) //获取脏数据收集器 GetDataArgs() *DataArgs //是否延时加载 IsDelayLoad() bool //是否为单一表加载,并有Limit,如果没有限制,Limit为-1 IsSingleTable() (result bool, limit int32) }
系统模块接口,
type IServicePlayer ¶
type IServicePlayer interface { IPlayer entity.IEntity IServiceModel //支持回调 CallDelay(cb func()) error //所有系统都加载完成后的调用 AllLoaded() //消息注册 RegMsgProc(interface{}) }
服务器上的PlayerNtt对象
type MapModel ¶
type MapModel struct { Data map[string]reflect.Value Table string DeletedAt gorm.DeletedAt `gorm:"index"` // contains filtered or unexported fields }
map的model,用来做部分字段更新
func NewMapModel ¶
func (*MapModel) SetPlayerID ¶
type ModuleBase ¶
type ModuleBase struct { Redisutil *DataUtil //redis操作 IsLoad bool //是否加载过 Args *DataArgs //标脏收集器 CallBreakFunc GetMsgForFunc //用于ModuleBase在SyncData里对单个数据进行生成数据的回调函数 // contains filtered or unexported fields }
实现IServiceModel接口的基类
func NewModuleBase ¶
func NewModuleBase(pid uint64) *ModuleBase
func (*ModuleBase) DelRedisDatas ¶
func (this *ModuleBase) DelRedisDatas(li map[string]IDataBaseModel, dbli []*protomsg.DBDataModel)
删redis里的数据
func (*ModuleBase) GetRedisTableDataAllDoMD ¶
func (this *ModuleBase) GetRedisTableDataAllDoMD(tnames []string) (result map[string][]IDataBaseModel, err error)
从redis里获取有关表的所有数据
func (*ModuleBase) GetRedisTableDataDoMD ¶
func (this *ModuleBase) GetRedisTableDataDoMD(tname string) (result []IDataBaseModel, err error)
从redis中读数据,支持分字段的结构
func (*ModuleBase) IsSingleTable ¶
func (this *ModuleBase) IsSingleTable() (result bool, limit int32)
是否为单一表加载,并有Limit,如果没有限制,Limit为-1
func (*ModuleBase) LoadData ¶
func (this *ModuleBase) LoadData(lis map[string][]IDataBaseModel)
同步加载的过程,一般是从redis里读出来后,再进行这个过程,不会失败
func (*ModuleBase) OtherData ¶
func (this *ModuleBase) OtherData(*protomsg.DBUpUserDatasReq)
他服逻辑-同步数据
func (*ModuleBase) OtherDataReqSrv ¶
func (this *ModuleBase) OtherDataReqSrv() []*protomsg.DBDataModel
请求他服数据
func (*ModuleBase) SaveRedis ¶
func (this *ModuleBase) SaveRedis(li map[string]IDataBaseModel, msg *protomsg.DBUpUserDatasReq)
保存数据到redis
func (*ModuleBase) SaveRedisDatas ¶
func (this *ModuleBase) SaveRedisDatas(li map[string]IDataBaseModel, dbli []*protomsg.DBDataModel)
func (*ModuleBase) SetRedisTableDataDoByte ¶
func (this *ModuleBase) SetRedisTableDataDoByte(data *MapModel) (err error)
写入redis,支持分字段的结构
type OtherSrvMsgProc ¶
type OtherSrvMsgProc struct {
// contains filtered or unexported fields
}
用来收DB来的数据
func NewOtherSrvMsgProc ¶
func NewOtherSrvMsgProc(pmd IPlayer) *OtherSrvMsgProc
func (*OtherSrvMsgProc) MsgProc_DBGetPlayerInfoAck ¶
func (this *OtherSrvMsgProc) MsgProc_DBGetPlayerInfoAck(imsg msgdef.IMsg)
func (*OtherSrvMsgProc) MsgProc_DBGetPlayerInfoEndAck ¶
func (this *OtherSrvMsgProc) MsgProc_DBGetPlayerInfoEndAck(imsg msgdef.IMsg)
func (*OtherSrvMsgProc) MsgProc_DBUpUserDatasReq ¶
func (this *OtherSrvMsgProc) MsgProc_DBUpUserDatasReq(imsg msgdef.IMsg)
收到他服的update数据
type PlayerBase ¶
type PlayerBase struct { PID uint64 `gorm:"primarykey;column:pid"` CreatedAt time.Time UpdatedAt time.Time DeletedAt gorm.DeletedAt `gorm:"index"` }
PlayerBase 一个角色一行数据的表基类
func (*PlayerBase) GetPlayerID ¶
func (md *PlayerBase) GetPlayerID() uint64
func (*PlayerBase) IsDeleted ¶
func (md *PlayerBase) IsDeleted() bool
func (*PlayerBase) SetDelete ¶
func (md *PlayerBase) SetDelete()
type PlayerSubBase ¶
type PlayerSubBase struct { ID uint64 `gorm:"primarykey"` CreatedAt time.Time UpdatedAt time.Time DeletedAt gorm.DeletedAt `gorm:"index"` PID uint64 `gorm:"index;column:pid"` }
PlayerSubBase 角色下的表基类
func (*PlayerSubBase) GetID ¶
func (md *PlayerSubBase) GetID() uint64
func (*PlayerSubBase) GetIsPartial ¶
func (md *PlayerSubBase) GetIsPartial() bool
(每个子系统都需要检查这个值返回的)是否支持单个字段更新
func (*PlayerSubBase) GetPlayerID ¶
func (md *PlayerSubBase) GetPlayerID() uint64
func (*PlayerSubBase) IsDeleted ¶
func (md *PlayerSubBase) IsDeleted() bool
func (*PlayerSubBase) SetDelete ¶
func (md *PlayerSubBase) SetDelete()
func (*PlayerSubBase) SetID ¶
func (md *PlayerSubBase) SetID(id uint64)
type TypeMgr ¶
type TypeMgr struct {
// contains filtered or unexported fields
}
TypeMgr 管理获取和保存需要落盘数据的管理器
func (*TypeMgr) GetModelByKeyName ¶
func (mgr *TypeMgr) GetModelByKeyName(keyname string) IDataBaseModel
GetModelByKeyName 按KeyName拿新实例
func (*TypeMgr) GetPlayerMainTableName ¶
GetPlayerMainTableName 拿到主表的名字
func (*TypeMgr) GetTableList ¶
func (mgr *TypeMgr) GetTableList() map[string]NewTableFunc
GetTableList 拿到所有表
func (*TypeMgr) GetTypeByTname ¶
func (mgr *TypeMgr) GetTypeByTname(tname string) IDataBaseModel
GetTypeByTname 按表拿到新实例