Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into liwei
This commit is contained in:
commit
aea5c31b9e
@ -32,7 +32,7 @@ func (r *Robot) handleFriendMsg(msg *pb.UserMessage) {
|
||||
func (r *Robot) FriendList() {
|
||||
req := &pb.FriendListReq{}
|
||||
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_List}
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.UserData.GetUid(), req)
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
||||
err := r.SendToClient(head, req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -53,7 +53,7 @@ func (r *Robot) FriendSearch(nickName string) {
|
||||
NickName: nickName,
|
||||
}
|
||||
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Search}
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.UserData.GetUid(), req)
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
||||
err := r.SendToClient(head, req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -74,7 +74,7 @@ func (r *Robot) FriendApply(friendId string) {
|
||||
FriendId: friendId,
|
||||
}
|
||||
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Apply}
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.UserData.GetUid(), req)
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
||||
err := r.SendToClient(head, req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -93,7 +93,7 @@ func (r *Robot) handleFriendApply(msg *pb.UserMessage) {
|
||||
func (r *Robot) FriendApplyList() {
|
||||
req := &pb.FriendApplyListReq{}
|
||||
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_ApplyList}
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.UserData.GetUid(), req)
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
||||
err := r.SendToClient(head, req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -114,7 +114,7 @@ func (r *Robot) FriendAgree(friendIds []string) {
|
||||
FriendIds: friendIds,
|
||||
}
|
||||
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Apply}
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.UserData.GetUid(), req)
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
||||
err := r.SendToClient(head, req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -135,7 +135,7 @@ func (r *Robot) FriendRefuse(friendIds []string) {
|
||||
FriendIds: friendIds,
|
||||
}
|
||||
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Refuse}
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.UserData.GetUid(), req)
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
||||
err := r.SendToClient(head, req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -154,7 +154,7 @@ func (r *Robot) handleFriendRefuse(msg *pb.UserMessage) {
|
||||
func (r *Robot) FriendBlacklist() {
|
||||
req := &pb.FriendBlackListReq{}
|
||||
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Blacklist}
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.UserData.GetUid(), req)
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
||||
err := r.SendToClient(head, req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -173,7 +173,7 @@ func (r *Robot) handleFriendBlacklist(msg *pb.UserMessage) {
|
||||
func (r *Robot) FriendAddBlack() {
|
||||
req := &pb.FriendBlackAddReq{}
|
||||
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_AddBlack}
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.UserData.GetUid(), req)
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
||||
err := r.SendToClient(head, req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -194,7 +194,7 @@ func (r *Robot) FriendDelBlack(friendId string) {
|
||||
FriendId: friendId,
|
||||
}
|
||||
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_DelBlack}
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.UserData.GetUid(), req)
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
||||
err := r.SendToClient(head, req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
@ -17,7 +17,7 @@ func (r *Robot) handlePackMsg(msg *pb.UserMessage) {
|
||||
func (r *Robot) QueryUserPack() {
|
||||
req := &pb.GetlistReq{IType: 1}
|
||||
head := &pb.UserMessage{MainType: "pack", SubType: "queryuserpackreq"}
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.UserData.GetUid(), req)
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
||||
err := r.SendToClient(head, req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
@ -3,6 +3,7 @@ package robot
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
"io/ioutil"
|
||||
@ -38,7 +39,7 @@ func (r *Robot) Run() {
|
||||
log.Printf("websocket %s \n", r.opts.WsUrl)
|
||||
|
||||
if r.opts.Create { //创建新用户
|
||||
r.AccountRegister()
|
||||
r.AccountRegister(r.opts.Account)
|
||||
} else {
|
||||
r.AccountLogin()
|
||||
}
|
||||
@ -90,7 +91,7 @@ func (r *Robot) onUserLoaded() {
|
||||
// r.FriendBlacklist()
|
||||
// r.FriendAddBlack()
|
||||
// r.FriendDelBlack("")
|
||||
r.FriendSearch("乐谷5")
|
||||
// r.FriendSearch("乐谷5")
|
||||
|
||||
//pack
|
||||
// r.QueryUserPack()
|
||||
@ -106,9 +107,12 @@ func (r *Robot) SendToClient(msg *pb.UserMessage, rsp proto.Message) error {
|
||||
}
|
||||
|
||||
//注册账号
|
||||
func (r *Robot) AccountRegister() {
|
||||
func (r *Robot) AccountRegister(account string) {
|
||||
if account == "" {
|
||||
log.Fatal("account value is empty")
|
||||
}
|
||||
//http
|
||||
regReq := &pb.UserRegisterReq{}
|
||||
regReq := &pb.UserRegisterReq{Account: account}
|
||||
jsonByte, _ := json.Marshal(regReq)
|
||||
req, err := http.NewRequest("POST", r.opts.RegUrl, bytes.NewReader(jsonByte))
|
||||
if err != nil {
|
||||
@ -128,6 +132,7 @@ func (r *Robot) AccountRegister() {
|
||||
|
||||
if regRsp.Code == pb.ErrorCode_Success { //注册成功
|
||||
|
||||
fmt.Printf("account:%s 注册成功", regRsp.Account)
|
||||
//登录
|
||||
loginReg := &pb.UserLoginReq{
|
||||
Sec: r.BuildSecStr(),
|
||||
|
@ -30,7 +30,7 @@ func (r *Robot) handleLogin(msg *pb.UserMessage) {
|
||||
r.user = rsp.Data
|
||||
r.onUserLoaded()
|
||||
} else {
|
||||
r.AccountRegister() //请求Http接口,模拟创建新账号
|
||||
r.AccountRegister(r.opts.Account) //请求Http接口,模拟创建新账号
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ func (r *Robot) CreateUser(NickName string) {
|
||||
SubType: user.User_SubType_Create,
|
||||
}
|
||||
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.UserData.GetUid(), req)
|
||||
defer traceFunc(head.MainType, head.SubType, r.user.GetUid(), req)
|
||||
err := r.SendToClient(head, req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
@ -142,16 +142,8 @@ func (this *Selector) ParseRoutRules(rules string) (result []string) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
for k, _ := range this.servers {
|
||||
iskeep := false
|
||||
if k == rules {
|
||||
iskeep = true
|
||||
break
|
||||
}
|
||||
if !iskeep {
|
||||
result = append(result, k)
|
||||
}
|
||||
if _, ok := this.servers[rules]; ok {
|
||||
result = append(result, rules)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"go_dreamfactory/pb"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
type (
|
||||
@ -26,7 +27,7 @@ type (
|
||||
// 向db 写日志信息
|
||||
InsertModelLogs(table string, uID string, target interface{}) (err error)
|
||||
DeleteModelLogs(table string, uID string, where interface{}) (err error)
|
||||
UpdateModelLogs(table string, uID string, where interface{}, target interface{}) (err error)
|
||||
UpdateModelLogs(table string, uID string, where bson.M, target interface{}) (err error)
|
||||
}
|
||||
IDB_Comp interface {
|
||||
}
|
||||
|
@ -1,16 +0,0 @@
|
||||
package dbservice
|
||||
|
||||
import (
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/core/cbase"
|
||||
)
|
||||
|
||||
// 邮件配置管理组件
|
||||
type Configure_Comp struct {
|
||||
cbase.ModuleCompBase
|
||||
}
|
||||
|
||||
func (this *Configure_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||
this.ModuleCompBase.Init(service, module, comp, options)
|
||||
return
|
||||
}
|
19
modules/dbservice/core.go
Normal file
19
modules/dbservice/core.go
Normal file
@ -0,0 +1,19 @@
|
||||
package dbservice
|
||||
|
||||
import (
|
||||
"go_dreamfactory/lego/core"
|
||||
)
|
||||
|
||||
const (
|
||||
WriteMaxNum uint32 = 1000 //一次性最处理条数
|
||||
ErrorMaxNum uint32 = 5 // 数据库操作最大失败次数
|
||||
TaskMaxNum uint32 = 1000 // 玩家离线消息队列长度
|
||||
)
|
||||
|
||||
var (
|
||||
ErrorLogCount = make(map[string]uint32, 0)
|
||||
)
|
||||
|
||||
const (
|
||||
DB_ModelTable core.SqlTable = "model_log"
|
||||
)
|
@ -6,64 +6,66 @@ import (
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/modules"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
const (
|
||||
WriteMaxNum uint32 = 1000 //一次性最处理条数
|
||||
ErrorMaxNum uint32 = 5 // 数据库操作最大失败次数
|
||||
)
|
||||
|
||||
var (
|
||||
ErrorLogCount = make(map[string]uint32, 0)
|
||||
)
|
||||
|
||||
type DB_Comp struct {
|
||||
modules.Model_Comp
|
||||
task chan string
|
||||
_data *mongo.Cursor
|
||||
}
|
||||
|
||||
// type data struct {
|
||||
// Table string
|
||||
// Wheremap map[string]interface{} // 如果是insert 条件就是nil del 只有条件
|
||||
// Modifymap map[string]map[string]interface{}
|
||||
// }
|
||||
|
||||
type QueryStruct struct {
|
||||
Selector bson.M
|
||||
Query bson.M
|
||||
func (this *DB_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||
this.Model_Comp.Init(service, module, comp, options)
|
||||
this.task = make(chan string, TaskMaxNum)
|
||||
this._data = new(mongo.Cursor)
|
||||
return
|
||||
}
|
||||
|
||||
const (
|
||||
DB_ModelTable core.SqlTable = "model_log"
|
||||
)
|
||||
func (this *DB_Comp) Start() (err error) {
|
||||
err = this.Model_Comp.Start()
|
||||
go this.run()
|
||||
return
|
||||
}
|
||||
|
||||
type IModel interface {
|
||||
Model_UpdateDBByLog() (err error) // 读取日志并更新对应的表
|
||||
Model_InsertDBByLog(data *comm.Autogenerated) (err error) // 插入日志
|
||||
func (this *DB_Comp) run() {
|
||||
for {
|
||||
select {
|
||||
case v := <-this.task:
|
||||
this.Model_UpdateDBByLog(v)
|
||||
case <-time.After(time.Second * 2):
|
||||
this.Model_UpdateDBByLog("")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (this *DB_Comp) PushUserTask(uid string) {
|
||||
this.task <- uid
|
||||
}
|
||||
|
||||
func (this *DB_Comp) Model_UpdateDBByLog(uid string) (err error) {
|
||||
_data := &mongo.Cursor{}
|
||||
|
||||
if uid == "" {
|
||||
_data, err = this.DB.Find(DB_ModelTable, bson.M{}, options.Find().SetLimit(int64(WriteMaxNum)))
|
||||
this._data, err = this.DB.Find(DB_ModelTable, bson.M{}, options.Find().SetLimit(int64(WriteMaxNum)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
_data, err = this.DB.Find(DB_ModelTable, bson.M{"uid": uid}, options.Find())
|
||||
this._data, err = this.DB.Find(DB_ModelTable, bson.M{"uid": uid}, options.Find())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
_delID := make([]string, 0) // 处理完成要删除的id
|
||||
for _data.Next(context.TODO()) { // 处理删除逻辑
|
||||
_delID := make([]string, 0) // 处理完成要删除的id
|
||||
for this._data.Next(context.TODO()) { // 处理删除逻辑
|
||||
|
||||
data := &comm.Autogenerated{}
|
||||
if err = _data.Decode(data); err != nil {
|
||||
if err = this._data.Decode(data); err != nil {
|
||||
log.Errorf("Decode Data err : %v", err)
|
||||
continue
|
||||
}
|
||||
@ -87,7 +89,7 @@ func (this *DB_Comp) Model_UpdateDBByLog(uid string) (err error) {
|
||||
log.Errorf("insert db err max num %s db err:%v", data.ID, err)
|
||||
_, err = this.DB.DeleteOne(DB_ModelTable, bson.M{"_id": data.ID})
|
||||
if err != nil {
|
||||
log.Errorf("insert %s db err:%v", data.ID, err)
|
||||
log.Errorf("insert %s db err:%+v", data.ID, err)
|
||||
}
|
||||
}
|
||||
continue
|
||||
@ -114,7 +116,7 @@ func (this *DB_Comp) Model_UpdateDBByLog(uid string) (err error) {
|
||||
log.Errorf("del db err max num %s db err:%v", data.ID, err)
|
||||
_, err = this.DB.DeleteOne(DB_ModelTable, bson.M{"_id": data.ID})
|
||||
if err != nil {
|
||||
log.Errorf("insert %s db err:%v", data.ID, err)
|
||||
log.Errorf("insert %s db err:%+v", data.ID, err)
|
||||
}
|
||||
}
|
||||
continue
|
||||
@ -124,17 +126,19 @@ func (this *DB_Comp) Model_UpdateDBByLog(uid string) (err error) {
|
||||
log.Errorf("parameter len _id : %s,uid : %s d.len:%v", data.ID, data.UID, len(data.D))
|
||||
continue
|
||||
}
|
||||
|
||||
_key := data.D[0].(string)
|
||||
where := data.D[1].(bson.D)
|
||||
_obj := &QueryStruct{}
|
||||
for _, v := range where {
|
||||
_obj.Selector[v.Key] = v
|
||||
Where := make(bson.M, 0)
|
||||
Query := make(bson.M, 0)
|
||||
Query1 := make(bson.M, 0)
|
||||
Query1["$set"] = Query
|
||||
for _, v := range data.D[1].(bson.D) {
|
||||
Where[v.Key] = v
|
||||
}
|
||||
query := data.D[2].(bson.D)
|
||||
for _, v := range query {
|
||||
_obj.Query[v.Key] = v
|
||||
for _, v := range data.D[2].(bson.D) {
|
||||
Query[v.Key] = v
|
||||
}
|
||||
_, err := this.DB.UpdateMany(core.SqlTable(_key), _obj.Selector, _obj.Query)
|
||||
_, err := this.DB.UpdateMany(core.SqlTable(_key), Where, Query1)
|
||||
if err != nil {
|
||||
log.Errorf("Update %s db err:%v", core.SqlTable(_key), err)
|
||||
ErrorLogCount[data.ID]++
|
||||
@ -142,7 +146,7 @@ func (this *DB_Comp) Model_UpdateDBByLog(uid string) (err error) {
|
||||
log.Errorf("update db err max num %s db err:%v", data.ID, err)
|
||||
_, err = this.DB.DeleteOne(DB_ModelTable, bson.M{"_id": data.ID})
|
||||
if err != nil {
|
||||
log.Errorf("insert %s db err:%v", data.ID, err)
|
||||
log.Errorf("insert %s db err:%+v", data.ID, err)
|
||||
}
|
||||
}
|
||||
continue
|
||||
@ -150,11 +154,14 @@ func (this *DB_Comp) Model_UpdateDBByLog(uid string) (err error) {
|
||||
}
|
||||
_delID = append(_delID, data.ID) // 都操作都成功了记录要删除的key
|
||||
}
|
||||
// 批量删除已处理的数据
|
||||
_, err = this.DB.DeleteMany(DB_ModelTable, bson.M{"_id": bson.M{"$in": _delID}}, options.Delete())
|
||||
if err != nil {
|
||||
log.Errorf("del err %v", err)
|
||||
|
||||
if len(_delID) > 0 {
|
||||
_, err = this.DB.DeleteMany(DB_ModelTable, bson.M{"_id": bson.M{"$in": _delID}}, options.Delete()) // 批量删除已处理的数据
|
||||
if err != nil {
|
||||
log.Errorf("del err %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -1,40 +0,0 @@
|
||||
package dbservice
|
||||
|
||||
import (
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/core/cbase"
|
||||
"time"
|
||||
)
|
||||
|
||||
type DBService_Comp struct {
|
||||
cbase.ModuleCompBase
|
||||
task chan string
|
||||
module *DBService
|
||||
}
|
||||
|
||||
func (this *DBService_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||
this.ModuleCompBase.Init(service, module, comp, options)
|
||||
this.module = module.(*DBService)
|
||||
return
|
||||
}
|
||||
|
||||
func (this *DBService_Comp) Start() (err error) {
|
||||
err = this.ModuleCompBase.Start()
|
||||
go this.run()
|
||||
return
|
||||
}
|
||||
|
||||
func (this *DBService_Comp) run() {
|
||||
for {
|
||||
select {
|
||||
case v := <-this.task:
|
||||
this.module.db_comp.Model_UpdateDBByLog(v)
|
||||
case <-time.After(time.Second * 2):
|
||||
this.module.db_comp.Model_UpdateDBByLog("")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (this *DBService_Comp) PushUserTask(uid string) {
|
||||
this.task <- uid
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package dbservice
|
||||
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/pb"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
var module = new(DBService)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
for i := 0; i < 50000; i++ {
|
||||
//go func() {
|
||||
_mail := &pb.DB_MailData{
|
||||
ObjId: primitive.NewObjectID().Hex(),
|
||||
UserId: "uid123",
|
||||
Title: "系统邮件",
|
||||
|
||||
Contex: "恭喜获得专属礼包一份",
|
||||
CreateTime: uint64(time.Now().Unix()),
|
||||
DueTime: uint64(time.Now().Unix()) + 30*24*3600,
|
||||
Check: false,
|
||||
Reward: false,
|
||||
}
|
||||
//db.InsertModelLogs("mail", "uid123", _mail)
|
||||
//InsertModelLogs("mail", "uid123", _mail)
|
||||
data := &comm.Autogenerated{
|
||||
ID: primitive.NewObjectID().Hex(),
|
||||
UID: "uid123",
|
||||
Act: string(comm.LogHandleType_Insert),
|
||||
}
|
||||
data.D = append(data.D, "mail") // D[0]
|
||||
data.D = append(data.D, _mail) // D[1]
|
||||
|
||||
_, err1 := module.db_comp.DB.InsertOne("model_log", data)
|
||||
if err1 != nil {
|
||||
log.Errorf("insert model db err %v", err1)
|
||||
}
|
||||
//}()
|
||||
}
|
||||
time.Sleep(time.Second * 10)
|
||||
defer os.Exit(m.Run())
|
||||
}
|
@ -13,10 +13,7 @@ func NewModule() core.IModule {
|
||||
|
||||
type DBService struct {
|
||||
modules.ModuleBase
|
||||
api_comp *Api_Comp
|
||||
db_comp *DB_Comp
|
||||
db_service *DBService_Comp
|
||||
configure_comp *Configure_Comp
|
||||
db_comp *DB_Comp
|
||||
}
|
||||
|
||||
func (this *DBService) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
||||
@ -31,8 +28,5 @@ func (this *DBService) GetType() core.M_Modules {
|
||||
|
||||
func (this *DBService) OnInstallComp() {
|
||||
this.ModuleBase.OnInstallComp()
|
||||
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp)
|
||||
this.db_comp = this.RegisterComp(new(DB_Comp)).(*DB_Comp)
|
||||
this.db_service = this.RegisterComp(new(DBService_Comp)).(*DBService_Comp)
|
||||
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp)
|
||||
}
|
||||
|
@ -1,19 +1,21 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/cache"
|
||||
"go_dreamfactory/utils"
|
||||
)
|
||||
|
||||
func (this *ApiComp) Addblack_Check(session comm.IUserSession, req *pb.FriendBlackAddReq) (result map[string]interface{}, code pb.ErrorCode) {
|
||||
return
|
||||
}
|
||||
|
||||
//加入黑名单
|
||||
func (this *ApiComp) Addblack(ctx context.Context, session comm.IUserSession, req *pb.FriendBlackAddReq) (err error) {
|
||||
func (this *ApiComp) Addblack(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendBlackAddReq) (err error) {
|
||||
var (
|
||||
code pb.ErrorCode
|
||||
self *pb.Cache_FriendData
|
||||
target *pb.Cache_FriendData
|
||||
self *pb.DB_FriendData
|
||||
target *pb.DB_FriendData
|
||||
rsp *pb.FriendBlackAddRsp
|
||||
blackNumMax = 50 //TODO 从配置中读取
|
||||
)
|
||||
@ -28,13 +30,13 @@ func (this *ApiComp) Addblack(ctx context.Context, session comm.IUserSession, re
|
||||
session.SendMsg(string(this.module.GetType()), Friend_SubType_AddBlack, code, rsp)
|
||||
}()
|
||||
|
||||
self, err = cache.Defsys.Friend_Get(session.GetUserId())
|
||||
err = this.module.model_friend.GetObj(session.GetUserId(), self)
|
||||
if self == nil || err != nil {
|
||||
code = pb.ErrorCode_FriendSelfNoData
|
||||
return
|
||||
}
|
||||
|
||||
target, err = cache.Defsys.Friend_Get(req.FriendId)
|
||||
err = this.module.model_friend.GetObj(req.FriendId, target)
|
||||
if target == nil || err != nil {
|
||||
code = pb.ErrorCode_FriendTargetNoData
|
||||
return
|
||||
@ -60,11 +62,8 @@ func (this *ApiComp) Addblack(ctx context.Context, session comm.IUserSession, re
|
||||
|
||||
//将目标加入黑名单
|
||||
self.BlackIds = append(self.BlackIds, req.FriendId)
|
||||
|
||||
//更新黑名单
|
||||
err = cache.Defsys.Friend_Update(self)
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
}
|
||||
this.module.model_friend.SetObj(self.UserId, self, false, true)
|
||||
return nil
|
||||
}
|
||||
|
@ -1,18 +1,20 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/cache"
|
||||
"go_dreamfactory/utils"
|
||||
)
|
||||
|
||||
func (this *ApiComp) Agree_Check(session comm.IUserSession, req *pb.FriendAgreeReq) (result map[string]interface{}, code pb.ErrorCode) {
|
||||
return
|
||||
}
|
||||
|
||||
//单个/批量同意
|
||||
func (this *ApiComp) Agree(ctx context.Context, session comm.IUserSession, req *pb.FriendAgreeReq) (err error) {
|
||||
func (this *ApiComp) Agree(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendAgreeReq) (err error) {
|
||||
var (
|
||||
code pb.ErrorCode
|
||||
self *pb.Cache_FriendData
|
||||
self *pb.DB_FriendData
|
||||
rsp *pb.FriendAgreeRsp
|
||||
optNum int32
|
||||
)
|
||||
@ -26,7 +28,7 @@ func (this *ApiComp) Agree(ctx context.Context, session comm.IUserSession, req *
|
||||
session.SendMsg(string(this.module.GetType()), Friend_SubType_Agree, code, rsp)
|
||||
}()
|
||||
|
||||
self, err = cache.Defsys.Friend_Get(session.GetUserId())
|
||||
err = this.module.model_friend.GetObj(session.GetUserId(), self)
|
||||
if self == nil || err != nil {
|
||||
code = pb.ErrorCode_FriendSelfNoData
|
||||
return
|
||||
@ -41,7 +43,8 @@ func (this *ApiComp) Agree(ctx context.Context, session comm.IUserSession, req *
|
||||
|
||||
//将自己加入到申请人的好友列表中
|
||||
for _, userId := range req.FriendIds {
|
||||
target, err2 := cache.Defsys.Friend_Get(userId)
|
||||
var target *pb.DB_FriendData
|
||||
err2 := this.module.model_friend.GetObj(userId, target)
|
||||
if target == nil || err2 != nil {
|
||||
code = pb.ErrorCode_FriendTargetNoData
|
||||
continue
|
||||
@ -49,11 +52,7 @@ func (this *ApiComp) Agree(ctx context.Context, session comm.IUserSession, req *
|
||||
if _, ok := utils.Find(target.FriendIds, self.UserId); !ok {
|
||||
target.FriendIds = append(target.FriendIds, self.UserId)
|
||||
}
|
||||
err = cache.Defsys.Friend_Update(target)
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
}
|
||||
this.module.model_friend.SetObj(target.UserId, target, false, true)
|
||||
}
|
||||
|
||||
//将申请人从申请列表中删除
|
||||
@ -63,10 +62,5 @@ func (this *ApiComp) Agree(ctx context.Context, session comm.IUserSession, req *
|
||||
}
|
||||
|
||||
//更新
|
||||
err = cache.Defsys.Friend_Update(self)
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
}
|
||||
return nil
|
||||
return this.module.model_friend.SetObj(self.UserId, self, false, true)
|
||||
}
|
||||
|
@ -1,20 +1,22 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/cache"
|
||||
"go_dreamfactory/utils"
|
||||
)
|
||||
|
||||
func (this *ApiComp) Apply_Check(session comm.IUserSession, req *pb.FriendApplyReq) (chk map[string]interface{}, code pb.ErrorCode) {
|
||||
return
|
||||
}
|
||||
|
||||
//好友申请
|
||||
func (this *ApiComp) Apply(ctx context.Context, session comm.IUserSession, req *pb.FriendApplyReq) (err error) {
|
||||
func (this *ApiComp) Apply(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendApplyReq) (err error) {
|
||||
var (
|
||||
code pb.ErrorCode
|
||||
self *pb.Cache_FriendData
|
||||
target *pb.Cache_FriendData
|
||||
self *pb.DB_FriendData
|
||||
target *pb.DB_FriendData
|
||||
rsp *pb.FriendApplyRsp
|
||||
)
|
||||
|
||||
@ -32,13 +34,13 @@ func (this *ApiComp) Apply(ctx context.Context, session comm.IUserSession, req *
|
||||
session.SendMsg(string(this.module.GetType()), Friend_SubType_Apply, code, rsp)
|
||||
}()
|
||||
|
||||
self, err = cache.Defsys.Friend_Get(session.GetUserId())
|
||||
err = this.module.model_friend.GetObj(session.GetUserId(), self)
|
||||
if self == nil || err != nil {
|
||||
code = pb.ErrorCode_FriendSelfNoData
|
||||
return
|
||||
}
|
||||
|
||||
target, err = cache.Defsys.Friend_Get(req.FriendId)
|
||||
err = this.module.model_friend.GetObj(req.FriendId, target)
|
||||
if target == nil || err != nil {
|
||||
code = pb.ErrorCode_FriendTargetNoData
|
||||
return
|
||||
@ -52,15 +54,15 @@ func (this *ApiComp) Apply(ctx context.Context, session comm.IUserSession, req *
|
||||
|
||||
//判断是否超过最大好友数量
|
||||
//TODO 最大数从全局配置中获取
|
||||
var max int32 = 50
|
||||
total := cache.Defsys.Friend_Total(session.GetUserId())
|
||||
var max int = 50
|
||||
total := len(self.FriendIds)
|
||||
if total >= max {
|
||||
code = pb.ErrorCode_FriendSelfMax
|
||||
return
|
||||
}
|
||||
|
||||
//判断对方是否也超过最大好友数量
|
||||
ttotal := cache.Defsys.Friend_Total(req.FriendId)
|
||||
ttotal := len(target.FriendIds)
|
||||
if ttotal >= max {
|
||||
code = pb.ErrorCode_FriendTargetMax
|
||||
return
|
||||
@ -92,10 +94,10 @@ func (this *ApiComp) Apply(ctx context.Context, session comm.IUserSession, req *
|
||||
|
||||
//将自己加入到目标用户的申请列表中
|
||||
target.ApplyIds = append(target.ApplyIds, self.UserId)
|
||||
err = cache.Defsys.Friend_Update(&pb.Cache_FriendData{
|
||||
err = this.module.model_friend.SetObj(req.FriendId, &pb.DB_FriendData{
|
||||
UserId: req.FriendId,
|
||||
ApplyIds: target.ApplyIds,
|
||||
})
|
||||
}, false, true)
|
||||
|
||||
if err != nil {
|
||||
log.Errorf("firend Apply err:%v", err)
|
||||
|
@ -1,17 +1,19 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/cache"
|
||||
)
|
||||
|
||||
func (this *ApiComp) ApplyList_Check(session comm.IUserSession, req *pb.FriendApplyListReq) (chk map[string]interface{}, code pb.ErrorCode) {
|
||||
return
|
||||
}
|
||||
|
||||
//申请列表
|
||||
func (this *ApiComp) ApplyList(ctx context.Context, session comm.IUserSession, req *pb.FriendApplyListReq) (err error) {
|
||||
func (this *ApiComp) ApplyList(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendApplyListReq) (err error) {
|
||||
var (
|
||||
code pb.ErrorCode
|
||||
self *pb.Cache_FriendData
|
||||
self *pb.DB_FriendData
|
||||
rsp *pb.FriendApplyListRsp
|
||||
list []*pb.FriendBase
|
||||
)
|
||||
@ -25,7 +27,7 @@ func (this *ApiComp) ApplyList(ctx context.Context, session comm.IUserSession, r
|
||||
session.SendMsg(string(this.module.GetType()), Friend_SubType_ApplyList, code, rsp)
|
||||
}()
|
||||
|
||||
self, err = cache.Defsys.Friend_Get(session.GetUserId())
|
||||
err = this.module.model_friend.GetObj(session.GetUserId(), self)
|
||||
if self == nil || err != nil {
|
||||
code = pb.ErrorCode_FriendSelfNoData
|
||||
return
|
||||
|
@ -1,17 +1,19 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/cache"
|
||||
)
|
||||
|
||||
func (this *ApiComp) Blacklist_Check(session comm.IUserSession, req *pb.FriendBlackListReq) (chk map[string]interface{}, code pb.ErrorCode) {
|
||||
return
|
||||
}
|
||||
|
||||
//黑名单
|
||||
func (this *ApiComp) Blacklist(ctx context.Context, session comm.IUserSession, req *pb.FriendBlackListReq) (err error) {
|
||||
func (this *ApiComp) Blacklist(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendBlackListReq) (err error) {
|
||||
var (
|
||||
code pb.ErrorCode
|
||||
self *pb.Cache_FriendData
|
||||
self *pb.DB_FriendData
|
||||
rsp *pb.FriendBlackListRsp
|
||||
list []*pb.FriendBase
|
||||
)
|
||||
@ -25,7 +27,7 @@ func (this *ApiComp) Blacklist(ctx context.Context, session comm.IUserSession, r
|
||||
session.SendMsg(string(this.module.GetType()), Friend_SubType_Blacklist, code, rsp)
|
||||
}()
|
||||
|
||||
self, err = cache.Defsys.Friend_Get(session.GetUserId())
|
||||
err = this.module.model_friend.GetObj(session.GetUserId(), self)
|
||||
if self == nil || err != nil {
|
||||
code = pb.ErrorCode_FriendSelfNoData
|
||||
return
|
||||
|
@ -1,12 +1,15 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
)
|
||||
|
||||
func (this *ApiComp) Del_Check(session comm.IUserSession, req *pb.FriendDelReq) (chk map[string]interface{}, code pb.ErrorCode) {
|
||||
return
|
||||
}
|
||||
|
||||
//删除好友
|
||||
func (this *ApiComp) Del(ctx context.Context, session comm.IUserSession, req *pb.FriendDelReq) error {
|
||||
func (this *ApiComp) Del(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendDelReq) error {
|
||||
return nil
|
||||
}
|
||||
|
@ -1,18 +1,20 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/cache"
|
||||
"go_dreamfactory/utils"
|
||||
)
|
||||
|
||||
func (this *ApiComp) Delblack_Check(session comm.IUserSession, req *pb.FriendDelBlackReq) (chk map[string]interface{}, code pb.ErrorCode) {
|
||||
return
|
||||
}
|
||||
|
||||
//删除黑名单
|
||||
func (this *ApiComp) delblack(ctx context.Context, session comm.IUserSession, req *pb.FriendDelBlackReq) (err error) {
|
||||
func (this *ApiComp) Delblack(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendDelBlackReq) (err error) {
|
||||
var (
|
||||
code pb.ErrorCode
|
||||
self *pb.Cache_FriendData
|
||||
self *pb.DB_FriendData
|
||||
rsp *pb.FriendDelBlackRsp
|
||||
)
|
||||
defer func() {
|
||||
@ -24,7 +26,7 @@ func (this *ApiComp) delblack(ctx context.Context, session comm.IUserSession, re
|
||||
}
|
||||
session.SendMsg(string(this.module.GetType()), Friend_SubType_AddBlack, code, rsp)
|
||||
}()
|
||||
self, err = cache.Defsys.Friend_Get(session.GetUserId())
|
||||
err = this.module.model_friend.GetObj(session.GetUserId(), self)
|
||||
if self == nil || err != nil {
|
||||
code = pb.ErrorCode_FriendSelfNoData
|
||||
return
|
||||
@ -33,10 +35,6 @@ func (this *ApiComp) delblack(ctx context.Context, session comm.IUserSession, re
|
||||
//从黑名单列表中删除目标
|
||||
self.BlackIds = utils.DeleteString(self.BlackIds, req.FriendId)
|
||||
//更新黑名单
|
||||
err = cache.Defsys.Friend_Update(self)
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
}
|
||||
return nil
|
||||
return this.module.model_friend.SetObj(self.UserId, self, false, true)
|
||||
|
||||
}
|
||||
|
@ -1,17 +1,19 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/cache"
|
||||
)
|
||||
|
||||
func (this *ApiComp) List_Check(session comm.IUserSession, req *pb.FriendListReq) (chk map[string]interface{}, code pb.ErrorCode) {
|
||||
return
|
||||
}
|
||||
|
||||
//好友列表
|
||||
func (this *ApiComp) List(ctx context.Context, session comm.IUserSession, req *pb.FriendListReq) (err error) {
|
||||
func (this *ApiComp) List(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendListReq) (err error) {
|
||||
var (
|
||||
code pb.ErrorCode
|
||||
self *pb.Cache_FriendData
|
||||
self *pb.DB_FriendData
|
||||
rsp *pb.FriendListRsp
|
||||
list []*pb.FriendBase
|
||||
)
|
||||
@ -25,7 +27,7 @@ func (this *ApiComp) List(ctx context.Context, session comm.IUserSession, req *p
|
||||
session.SendMsg(string(this.module.GetType()), Friend_SubType_List, code, rsp)
|
||||
}()
|
||||
|
||||
self, err = cache.Defsys.Friend_Get(session.GetUserId())
|
||||
err = this.module.model_friend.GetObj(session.GetUserId(), self)
|
||||
if self == nil || err != nil {
|
||||
code = pb.ErrorCode_FriendSelfNoData
|
||||
return
|
||||
|
@ -1,19 +1,21 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/cache"
|
||||
"go_dreamfactory/utils"
|
||||
)
|
||||
|
||||
func (this *ApiComp) Refuse_Check(session comm.IUserSession, req *pb.FriendRefuseReq) (chk map[string]interface{}, code pb.ErrorCode) {
|
||||
return
|
||||
}
|
||||
|
||||
//单个/批量拒绝
|
||||
func (this *ApiComp) Refuse(ctx context.Context, session comm.IUserSession, req *pb.FriendRefuseReq) (err error) {
|
||||
func (this *ApiComp) Refuse(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendRefuseReq) (err error) {
|
||||
//将申请人从申请列表中删除
|
||||
var (
|
||||
code pb.ErrorCode
|
||||
self *pb.Cache_FriendData
|
||||
self *pb.DB_FriendData
|
||||
rsp *pb.FriendAgreeRsp
|
||||
optNum int32
|
||||
)
|
||||
@ -26,7 +28,7 @@ func (this *ApiComp) Refuse(ctx context.Context, session comm.IUserSession, req
|
||||
session.SendMsg(string(this.module.GetType()), Friend_SubType_Refuse, code, rsp)
|
||||
}()
|
||||
|
||||
self, err = cache.Defsys.Friend_Get(session.GetUserId())
|
||||
err = this.module.model_friend.GetObj(session.GetUserId(), self)
|
||||
if self == nil || err != nil {
|
||||
code = pb.ErrorCode_FriendSelfNoData
|
||||
return
|
||||
@ -39,10 +41,5 @@ func (this *ApiComp) Refuse(ctx context.Context, session comm.IUserSession, req
|
||||
}
|
||||
|
||||
//更新
|
||||
err = cache.Defsys.Friend_Update(self)
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
}
|
||||
return nil
|
||||
return this.module.model_friend.SetObj(self.UserId, self, false, true)
|
||||
}
|
||||
|
@ -1,13 +1,16 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
)
|
||||
|
||||
func (this *ApiComp) Search_Check(session comm.IUserSession, req *pb.FriendSearchReq) (chk map[string]interface{}, code pb.ErrorCode) {
|
||||
return
|
||||
}
|
||||
|
||||
//搜索
|
||||
func (this *ApiComp) Search(ctx context.Context, session comm.IUserSession, req *pb.FriendSearchReq) error {
|
||||
func (this *ApiComp) Search(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendSearchReq) error {
|
||||
var (
|
||||
code pb.ErrorCode
|
||||
rsp *pb.FriendSearchRsp
|
||||
@ -22,7 +25,7 @@ func (this *ApiComp) Search(ctx context.Context, session comm.IUserSession, req
|
||||
session.SendMsg(string(this.module.GetType()), Friend_SubType_Search, code, rsp)
|
||||
}()
|
||||
|
||||
user :=this.module.model_friend.Frined_FindCond(req.NickName)
|
||||
user := this.module.model_friend.Frined_FindCond(req.NickName)
|
||||
if user != nil {
|
||||
friend = &pb.FriendBase{
|
||||
UserId: user.Uid,
|
||||
|
@ -27,7 +27,7 @@ func (this *ModelFriend) Init(service core.IService, module core.IModule, comp c
|
||||
}
|
||||
|
||||
//好友
|
||||
func (this *ModelFriend) Friend_SaveOrUpdate(data *pb.Cache_FriendData) (err error) {
|
||||
func (this *ModelFriend) Friend_SaveOrUpdate(data *pb.DB_FriendData) (err error) {
|
||||
err = this.DB.FindOneAndUpdate(DB_FriendTable,
|
||||
bson.M{"_id": data.UserId},
|
||||
bson.M{"$set": bson.M{
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"go_dreamfactory/pb"
|
||||
)
|
||||
|
||||
func (this *Api_Comp) GetUserMailAttachmentReq_Check(session comm.IUserSession, req *pb.DelUserMailReq) (result map[string]interface{}, code pb.ErrorCode) {
|
||||
func (this *Api_Comp) GetUserMailAttachmentReq_Check(session comm.IUserSession, req *pb.GetUserMailAttachmentReq) (result map[string]interface{}, code pb.ErrorCode) {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"go_dreamfactory/pb"
|
||||
)
|
||||
|
||||
func (this *Api_Comp) QueryUserMailReq_Check(session comm.IUserSession, req *pb.DelUserMailReq) (result map[string]interface{}, code pb.ErrorCode) {
|
||||
func (this *Api_Comp) QueryUserMailReq_Check(session comm.IUserSession, req *pb.QueryUserMailReq) (result map[string]interface{}, code pb.ErrorCode) {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"go_dreamfactory/pb"
|
||||
)
|
||||
|
||||
func (this *Api_Comp) ReadUserMailReq_Check(session comm.IUserSession, req *pb.DelUserMailReq) (result map[string]interface{}, code pb.ErrorCode) {
|
||||
func (this *Api_Comp) ReadUserMailReq_Check(session comm.IUserSession, req *pb.ReadUserMailReq) (result map[string]interface{}, code pb.ErrorCode) {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/modules"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/cache"
|
||||
"time"
|
||||
|
||||
"go_dreamfactory/lego/core"
|
||||
@ -57,8 +56,9 @@ func (this *Mail) CreateNewMail(uId string) {
|
||||
log.Error("create mail failed")
|
||||
}
|
||||
// 通知玩家
|
||||
_cache := cache.Defsys.Get(uId)
|
||||
if _cache == nil {
|
||||
var _cache *pb.Cache_UserData
|
||||
err = this.db_comp.Model_Comp.GetObj(uId, _cache)
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
/*
|
||||
@ -78,7 +79,7 @@ func (this *Model_Comp) DeleteModelLogs(table string, uID string, where interfac
|
||||
return err
|
||||
}
|
||||
|
||||
func (this *Model_Comp) UpdateModelLogs(table string, uID string, where interface{}, target interface{}) (err error) {
|
||||
func (this *Model_Comp) UpdateModelLogs(table string, uID string, where bson.M, target interface{}) (err error) {
|
||||
|
||||
data := &comm.Autogenerated{
|
||||
ID: primitive.NewObjectID().Hex(),
|
||||
@ -97,20 +98,44 @@ func (this *Model_Comp) UpdateModelLogs(table string, uID string, where interfac
|
||||
return err
|
||||
}
|
||||
|
||||
func (this *Model_Comp) SetObj(uid string, data proto.Message, isnew, islog bool) error {
|
||||
err := this.Redis.Set(fmt.Sprintf("%s:%s", this.Prefix, uid), data, 0)
|
||||
if err != nil {
|
||||
log.Errorf("set err:%v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if islog {
|
||||
if isnew {
|
||||
return this.InsertModelLogs(this.Prefix, uid, data)
|
||||
} else {
|
||||
return this.UpdateModelLogs(this.Prefix, uid, bson.M{"_id": uid}, data)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//更新缓存字段
|
||||
func (this *Model_Comp) Set(uid string, v map[string]interface{}, isnew bool) error {
|
||||
//isnew true insertlog , false updatelog
|
||||
func (this *Model_Comp) Set(uid string, v map[string]interface{}, isnew, islog bool) error {
|
||||
err := this.Redis.HMSet(fmt.Sprintf("%s:%s", this.Prefix, uid), v)
|
||||
if err != nil {
|
||||
log.Errorf("set err:%v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if isnew {
|
||||
return this.InsertModelLogs(this.Prefix, uid, v)
|
||||
} else {
|
||||
return this.UpdateModelLogs(this.Prefix, uid, bson.M{"_id": uid}, v)
|
||||
if islog {
|
||||
if isnew {
|
||||
return this.InsertModelLogs(this.Prefix, uid, v)
|
||||
} else {
|
||||
return this.UpdateModelLogs(this.Prefix, uid, bson.M{"_id": uid}, v)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *Model_Comp) GetObj(uid string, v interface{}) error {
|
||||
return this.Redis.Get(fmt.Sprintf("%s:%s", this.Prefix, uid), v)
|
||||
}
|
||||
|
||||
//获取对象数据
|
||||
|
@ -17,12 +17,19 @@ const ( //消息回复的头名称
|
||||
*/
|
||||
type Api_Comp struct {
|
||||
modules.MComp_GateComp
|
||||
module *Pack
|
||||
service core.IService
|
||||
module *Pack
|
||||
}
|
||||
|
||||
//组件初始化接口
|
||||
func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||
this.MComp_GateComp.Init(service, module, comp, options)
|
||||
this.module = module.(*Pack)
|
||||
this.service = service
|
||||
return
|
||||
}
|
||||
|
||||
func (this *Api_Comp) Start() (err error) {
|
||||
err = this.MComp_GateComp.Start()
|
||||
return
|
||||
}
|
||||
|
@ -1,25 +1,27 @@
|
||||
package dbservice
|
||||
package user
|
||||
|
||||
import (
|
||||
"go_dreamfactory/modules"
|
||||
|
||||
"go_dreamfactory/lego/base"
|
||||
"go_dreamfactory/lego/core"
|
||||
)
|
||||
|
||||
const (
|
||||
User_SubType_Login = "login"
|
||||
User_SubType_Logout = "logout"
|
||||
User_SubType_Create = "create"
|
||||
)
|
||||
|
||||
type Api_Comp struct {
|
||||
modules.MComp_GateComp
|
||||
service core.IService
|
||||
module *DBService
|
||||
service base.IRPCXService
|
||||
module *User
|
||||
}
|
||||
|
||||
func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||
this.MComp_GateComp.Init(service, module, comp, options)
|
||||
this.service = service
|
||||
this.module = module.(*DBService)
|
||||
return
|
||||
}
|
||||
|
||||
func (this *Api_Comp) Start() (err error) {
|
||||
|
||||
this.service = service.(base.IRPCXService)
|
||||
this.module = module.(*User)
|
||||
return
|
||||
}
|
@ -1,33 +1,18 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/modules"
|
||||
"go_dreamfactory/lego/sys/event"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/utils"
|
||||
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/event"
|
||||
)
|
||||
|
||||
const (
|
||||
User_SubType_Create = "create"
|
||||
)
|
||||
|
||||
type UserComp struct {
|
||||
modules.MComp_GateComp
|
||||
module *User
|
||||
}
|
||||
|
||||
func (this *UserComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||
this.MComp_GateComp.Init(service, module, comp, options)
|
||||
this.module = module.(*User)
|
||||
func (this *Api_Comp) Create_Check(session comm.IUserSession, req *pb.UserCreateReq) (result map[string]interface{}, code pb.ErrorCode) {
|
||||
return
|
||||
}
|
||||
|
||||
//创角
|
||||
func (this *UserComp) Create(ctx context.Context, session comm.IUserSession, req *pb.UserCreateReq) (err error) {
|
||||
func (this *Api_Comp) Create(session comm.IUserSession, result map[string]interface{}, req *pb.UserCreateReq) (err error) {
|
||||
defer utils.TraceFunc(session.GetUserId(), string(this.module.GetType()), User_SubType_Create, req, nil)
|
||||
|
||||
var code pb.ErrorCode
|
||||
@ -39,7 +24,7 @@ func (this *UserComp) Create(ctx context.Context, session comm.IUserSession, req
|
||||
update := map[string]interface{}{
|
||||
"name": req.NickName,
|
||||
}
|
||||
err = this.module.modelUser.Set(session.GetUserId(), update)
|
||||
err = this.module.modelUser.Set(session.GetUserId(), update, false, true)
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
@ -1,37 +1,18 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/modules"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/db"
|
||||
"go_dreamfactory/utils"
|
||||
"time"
|
||||
|
||||
"go_dreamfactory/lego/base"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/event"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/utils"
|
||||
"time"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
)
|
||||
|
||||
type LoginComp struct {
|
||||
modules.MComp_GateComp
|
||||
service base.IRPCXService
|
||||
model *User
|
||||
}
|
||||
|
||||
func (this *LoginComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||
this.MComp_GateComp.Init(service, module, comp, options)
|
||||
this.service = service.(base.IRPCXService)
|
||||
this.model = module.(*User)
|
||||
return
|
||||
}
|
||||
|
||||
//解码
|
||||
func decodeUserData(base64Str string) *pb.DB_UserData {
|
||||
dec, err := base64.StdEncoding.DecodeString(base64Str[35:])
|
||||
@ -53,8 +34,14 @@ func decodeUserData(base64Str string) *pb.DB_UserData {
|
||||
}
|
||||
}
|
||||
|
||||
//参数校验
|
||||
func (this *Api_Comp) Login_Check(session comm.IUserSession, req *pb.UserLoginReq) (result map[string]interface{}, code pb.ErrorCode) {
|
||||
result = map[string]interface{}{}
|
||||
return
|
||||
}
|
||||
|
||||
//登录
|
||||
func (this *LoginComp) Login(ctx context.Context, session comm.IUserSession, req *pb.UserLoginReq) (err error) {
|
||||
func (this *Api_Comp) Login(session comm.IUserSession, result map[string]interface{}, req *pb.UserLoginReq) (err error) {
|
||||
var (
|
||||
code pb.ErrorCode
|
||||
db_user *pb.DB_UserData
|
||||
@ -62,7 +49,7 @@ func (this *LoginComp) Login(ctx context.Context, session comm.IUserSession, req
|
||||
|
||||
defer func() {
|
||||
if db_user != nil {
|
||||
session.SendMsg("user", "login", code, &pb.UserLoginResp{
|
||||
session.SendMsg(string(this.module.GetType()), User_SubType_Login, code, &pb.UserLoginResp{
|
||||
Data: &pb.Cache_UserData{
|
||||
Uid: db_user.Id,
|
||||
},
|
||||
@ -78,7 +65,7 @@ func (this *LoginComp) Login(ctx context.Context, session comm.IUserSession, req
|
||||
|
||||
user := decodeUserData(req.Sec)
|
||||
|
||||
db_user, err = db.Defsys.User_FindByAccount(user)
|
||||
db_user, err = this.module.modelUser.User_FindByAccount(user)
|
||||
if err != nil {
|
||||
if err != mongo.ErrNoDocuments {
|
||||
return err
|
||||
@ -92,34 +79,34 @@ func (this *LoginComp) Login(ctx context.Context, session comm.IUserSession, req
|
||||
|
||||
//如果是新玩家,创建一条基础的数据,页面会引导进入创角页面
|
||||
if db_user == nil {
|
||||
err = db.Defsys.User_Create(user)
|
||||
//新玩家
|
||||
err = this.module.modelUser.User_Create(user)
|
||||
if err != nil {
|
||||
log.Errorf("User_CreateUser err %v", err)
|
||||
return
|
||||
}
|
||||
session.Bind(user.Uid, this.service.GetId())
|
||||
cache_user.Uid = user.Uid
|
||||
// data := map[string]interface{}{
|
||||
// "sessionId": cache_user.SessionId,
|
||||
// "gatewayServiceId": cache_user.GatewayServiceId,
|
||||
// }
|
||||
data := &pb.Cache_UserData{
|
||||
Uid: user.Uid,
|
||||
SessionId: cache_user.SessionId,
|
||||
GatewayServiceId: cache_user.GatewayServiceId,
|
||||
}
|
||||
return this.module.modelUser.SetObj(cache_user.Uid, data, true, true)
|
||||
} else {
|
||||
session.Bind(db_user.Uid, this.service.GetId())
|
||||
cache_user.Uid = db_user.Uid
|
||||
data := &pb.Cache_UserData{
|
||||
Uid: db_user.Uid,
|
||||
SessionId: cache_user.SessionId,
|
||||
GatewayServiceId: cache_user.GatewayServiceId,
|
||||
}
|
||||
// data := map[string]interface{}{
|
||||
// "sessionId": cache_user.SessionId,
|
||||
// "gatewayServiceId": cache_user.GatewayServiceId,
|
||||
// }
|
||||
return this.module.modelUser.SetObj(cache_user.Uid, data, false, false)
|
||||
}
|
||||
// data := map[string]interface{}{
|
||||
// "sessionId": cache_user.SessionId,
|
||||
// "gatewayServiceId": cache_user.GatewayServiceId,
|
||||
// }
|
||||
// this.model.ModuleBas.Set(cache_user.Uid, data)
|
||||
// err = cache.Defsys.Update(cache_user)
|
||||
// if err != nil {
|
||||
// log.Errorf("update cache err:%v", err)
|
||||
// return err
|
||||
// }
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
//注销
|
||||
func (this *LoginComp) Logout(ctx context.Context, session comm.IUserSession, rsp *pb.UserLoginReq) error {
|
||||
log.Debugf("User - Logout: session:%v rsp:%v", session.ToString(), rsp)
|
||||
|
||||
return nil
|
||||
}
|
18
modules/user/api_logout.go
Normal file
18
modules/user/api_logout.go
Normal file
@ -0,0 +1,18 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/pb"
|
||||
)
|
||||
|
||||
func (this *Api_Comp) Logout_Check(session comm.IUserSession, req *pb.UserLoginReq) (result map[string]interface{}, code pb.ErrorCode) {
|
||||
return
|
||||
}
|
||||
|
||||
//注销
|
||||
func (this *Api_Comp) Logout(session comm.IUserSession, result map[string]interface{}, rsp *pb.UserLoginReq) error {
|
||||
log.Debugf("User - Logout: session:%v rsp:%v", session.ToString(), rsp)
|
||||
|
||||
return nil
|
||||
}
|
@ -1,8 +1,20 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/modules"
|
||||
"go_dreamfactory/pb"
|
||||
"time"
|
||||
|
||||
uuid "github.com/satori/go.uuid"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
const ( //Redis
|
||||
DB_UserTable core.SqlTable = "user" //用户表
|
||||
)
|
||||
|
||||
type ModelUser struct {
|
||||
@ -15,3 +27,46 @@ func (this *ModelUser) Init(service core.IService, module core.IModule, comp cor
|
||||
return
|
||||
}
|
||||
|
||||
func (this *ModelUser) User_FindByAccount(user *pb.DB_UserData) (*pb.DB_UserData, error) {
|
||||
filter := bson.M{
|
||||
"sid": user.Sid,
|
||||
"binduid": user.Binduid,
|
||||
}
|
||||
sr := this.DB.FindOne(DB_UserTable, filter)
|
||||
var nd *pb.DB_UserData
|
||||
err := sr.Decode(&nd)
|
||||
return nd, err
|
||||
}
|
||||
|
||||
func (this *ModelUser) User_FindById(id string) (*pb.DB_UserData, error) {
|
||||
filter := bson.M{
|
||||
"userid": id,
|
||||
}
|
||||
sr := this.DB.FindOne(DB_UserTable, filter)
|
||||
user := &pb.DB_UserData{}
|
||||
err := sr.Decode(user)
|
||||
return user, err
|
||||
}
|
||||
|
||||
func (this *ModelUser) User_Create(user *pb.DB_UserData) (err error) {
|
||||
_id := primitive.NewObjectID().Hex()
|
||||
user.Id = _id
|
||||
user.Uid = fmt.Sprintf("%d_%s", user.Sid, _id)
|
||||
user.Uuid = uuid.NewV4().String()
|
||||
user.Ctime = time.Now().Unix()
|
||||
_, err = this.DB.InsertOne(DB_UserTable, user)
|
||||
return err
|
||||
}
|
||||
|
||||
//更新用户数据到DB
|
||||
func (this *ModelUser) User_Update(data *pb.DB_UserData) (err error) {
|
||||
err = this.DB.FindOneAndUpdate(
|
||||
DB_UserTable,
|
||||
bson.M{"uid": data.Uid},
|
||||
bson.M{"$set": bson.M{
|
||||
"name": data.Name,
|
||||
}},
|
||||
options.FindOneAndUpdate().SetUpsert(true),
|
||||
).Err()
|
||||
return err
|
||||
}
|
||||
|
@ -14,8 +14,7 @@ func NewModule() core.IModule {
|
||||
|
||||
type User struct {
|
||||
modules.ModuleBase
|
||||
login_comp *LoginComp
|
||||
user_comp *UserComp
|
||||
user_comp *Api_Comp
|
||||
modelUser *ModelUser
|
||||
}
|
||||
|
||||
@ -31,7 +30,6 @@ func (this *User) Init(service core.IService, module core.IModule, options core.
|
||||
|
||||
func (this *User) OnInstallComp() {
|
||||
this.ModuleBase.OnInstallComp()
|
||||
this.login_comp = this.RegisterComp(new(LoginComp)).(*LoginComp)
|
||||
this.user_comp = this.RegisterComp(new(UserComp)).(*UserComp)
|
||||
this.user_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp)
|
||||
this.modelUser = this.RegisterComp(new(ModelUser)).(*ModelUser)
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package web
|
||||
|
||||
import (
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/db"
|
||||
"net/http"
|
||||
|
||||
"go_dreamfactory/lego/core"
|
||||
@ -26,6 +25,7 @@ type Api_Comp struct {
|
||||
func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||
err = this.ModuleCompBase.Init(service, module, comp, options)
|
||||
this.options = options.(*Options)
|
||||
this.module = module.(*Web)
|
||||
this.gin, err = gin.NewSys(gin.SetListenPort(this.options.Port))
|
||||
this.gin.POST("/register", this.Register)
|
||||
return
|
||||
@ -37,7 +37,7 @@ func (this *Api_Comp) Register(c *engine.Context) {
|
||||
rsp := &pb.UserRegisterRsp{}
|
||||
err := c.BindJSON(&req)
|
||||
if err == nil {
|
||||
err := db.Defsys.User_Create(&pb.DB_UserData{
|
||||
err := this.module.modelUser.User_Create(&pb.DB_UserData{
|
||||
Binduid: req.Account,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -3,6 +3,7 @@ package web
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/modules"
|
||||
"go_dreamfactory/modules/user"
|
||||
|
||||
"go_dreamfactory/lego/core"
|
||||
)
|
||||
@ -19,8 +20,9 @@ func NewModule() core.IModule {
|
||||
|
||||
type Web struct {
|
||||
modules.ModuleBase
|
||||
options *Options
|
||||
api_comp *Api_Comp //提供weba pi服务的组件
|
||||
options *Options
|
||||
api_comp *Api_Comp //提供weba pi服务的组件
|
||||
modelUser *user.ModelUser
|
||||
}
|
||||
|
||||
//模块名
|
||||
@ -42,4 +44,5 @@ func (this *Web) Init(service core.IService, module core.IModule, options core.I
|
||||
func (this *Web) OnInstallComp() {
|
||||
this.ModuleBase.OnInstallComp()
|
||||
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp)
|
||||
this.modelUser = this.RegisterComp(new(user.ModelUser)).(*user.ModelUser)
|
||||
}
|
||||
|
@ -27,10 +27,10 @@ type UserMessage struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
MainType string `protobuf:"bytes,1,opt,name=MainType,proto3" json:"MainType,omitempty"`
|
||||
SubType string `protobuf:"bytes,2,opt,name=SubType,proto3" json:"SubType,omitempty"`
|
||||
Code ErrorCode `protobuf:"varint,3,opt,name=Code,proto3,enum=ErrorCode" json:"Code,omitempty"`
|
||||
Data *anypb.Any `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"`
|
||||
MainType string `protobuf:"bytes,1,opt,name=MainType,proto3" json:"MainType"`
|
||||
SubType string `protobuf:"bytes,2,opt,name=SubType,proto3" json:"SubType"`
|
||||
Code ErrorCode `protobuf:"varint,3,opt,name=Code,proto3,enum=ErrorCode" json:"Code"`
|
||||
Data *anypb.Any `protobuf:"bytes,4,opt,name=data,proto3" json:"data"`
|
||||
}
|
||||
|
||||
func (x *UserMessage) Reset() {
|
||||
@ -99,12 +99,12 @@ type AgentMessage struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Ip string `protobuf:"bytes,1,opt,name=Ip,proto3" json:"Ip,omitempty"`
|
||||
UserSessionId string `protobuf:"bytes,2,opt,name=UserSessionId,proto3" json:"UserSessionId,omitempty"`
|
||||
UserId string `protobuf:"bytes,3,opt,name=UserId,proto3" json:"UserId,omitempty"`
|
||||
GatewayServiceId string `protobuf:"bytes,4,opt,name=GatewayServiceId,proto3" json:"GatewayServiceId,omitempty"`
|
||||
Method string `protobuf:"bytes,5,opt,name=Method,proto3" json:"Method,omitempty"`
|
||||
Message *anypb.Any `protobuf:"bytes,6,opt,name=Message,proto3" json:"Message,omitempty"`
|
||||
Ip string `protobuf:"bytes,1,opt,name=Ip,proto3" json:"Ip"`
|
||||
UserSessionId string `protobuf:"bytes,2,opt,name=UserSessionId,proto3" json:"UserSessionId"`
|
||||
UserId string `protobuf:"bytes,3,opt,name=UserId,proto3" json:"UserId"`
|
||||
GatewayServiceId string `protobuf:"bytes,4,opt,name=GatewayServiceId,proto3" json:"GatewayServiceId"`
|
||||
Method string `protobuf:"bytes,5,opt,name=Method,proto3" json:"Method"`
|
||||
Message *anypb.Any `protobuf:"bytes,6,opt,name=Message,proto3" json:"Message"`
|
||||
}
|
||||
|
||||
func (x *AgentMessage) Reset() {
|
||||
@ -187,8 +187,8 @@ type RPCMessageReply struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Code ErrorCode `protobuf:"varint,1,opt,name=Code,proto3,enum=ErrorCode" json:"Code,omitempty"`
|
||||
Msg string `protobuf:"bytes,2,opt,name=Msg,proto3" json:"Msg,omitempty"`
|
||||
Code ErrorCode `protobuf:"varint,1,opt,name=Code,proto3,enum=ErrorCode" json:"Code"`
|
||||
Msg string `protobuf:"bytes,2,opt,name=Msg,proto3" json:"Msg"`
|
||||
}
|
||||
|
||||
func (x *RPCMessageReply) Reset() {
|
||||
@ -243,9 +243,9 @@ type AgentBuildReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
UserSessionId string `protobuf:"bytes,1,opt,name=UserSessionId,proto3" json:"UserSessionId,omitempty"`
|
||||
UserId string `protobuf:"bytes,2,opt,name=UserId,proto3" json:"UserId,omitempty"`
|
||||
WorkerId string `protobuf:"bytes,3,opt,name=WorkerId,proto3" json:"WorkerId,omitempty"`
|
||||
UserSessionId string `protobuf:"bytes,1,opt,name=UserSessionId,proto3" json:"UserSessionId"`
|
||||
UserId string `protobuf:"bytes,2,opt,name=UserId,proto3" json:"UserId"`
|
||||
WorkerId string `protobuf:"bytes,3,opt,name=WorkerId,proto3" json:"WorkerId"`
|
||||
}
|
||||
|
||||
func (x *AgentBuildReq) Reset() {
|
||||
@ -307,7 +307,7 @@ type AgentUnBuildReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
UserSessionId string `protobuf:"bytes,1,opt,name=UserSessionId,proto3" json:"UserSessionId,omitempty"`
|
||||
UserSessionId string `protobuf:"bytes,1,opt,name=UserSessionId,proto3" json:"UserSessionId"`
|
||||
}
|
||||
|
||||
func (x *AgentUnBuildReq) Reset() {
|
||||
@ -355,11 +355,11 @@ type AgentSendMessageReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
UserSessionId string `protobuf:"bytes,1,opt,name=UserSessionId,proto3" json:"UserSessionId,omitempty"`
|
||||
MainType string `protobuf:"bytes,2,opt,name=MainType,proto3" json:"MainType,omitempty"`
|
||||
SubType string `protobuf:"bytes,3,opt,name=SubType,proto3" json:"SubType,omitempty"`
|
||||
Code ErrorCode `protobuf:"varint,4,opt,name=Code,proto3,enum=ErrorCode" json:"Code,omitempty"`
|
||||
Data *anypb.Any `protobuf:"bytes,5,opt,name=Data,proto3" json:"Data,omitempty"`
|
||||
UserSessionId string `protobuf:"bytes,1,opt,name=UserSessionId,proto3" json:"UserSessionId"`
|
||||
MainType string `protobuf:"bytes,2,opt,name=MainType,proto3" json:"MainType"`
|
||||
SubType string `protobuf:"bytes,3,opt,name=SubType,proto3" json:"SubType"`
|
||||
Code ErrorCode `protobuf:"varint,4,opt,name=Code,proto3,enum=ErrorCode" json:"Code"`
|
||||
Data *anypb.Any `protobuf:"bytes,5,opt,name=Data,proto3" json:"Data"`
|
||||
}
|
||||
|
||||
func (x *AgentSendMessageReq) Reset() {
|
||||
@ -435,10 +435,10 @@ type BatchMessageReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
UserSessionIds []string `protobuf:"bytes,1,rep,name=UserSessionIds,proto3" json:"UserSessionIds,omitempty"`
|
||||
MainType string `protobuf:"bytes,2,opt,name=MainType,proto3" json:"MainType,omitempty"`
|
||||
SubType string `protobuf:"bytes,3,opt,name=SubType,proto3" json:"SubType,omitempty"`
|
||||
Data *anypb.Any `protobuf:"bytes,4,opt,name=Data,proto3" json:"Data,omitempty"`
|
||||
UserSessionIds []string `protobuf:"bytes,1,rep,name=UserSessionIds,proto3" json:"UserSessionIds"`
|
||||
MainType string `protobuf:"bytes,2,opt,name=MainType,proto3" json:"MainType"`
|
||||
SubType string `protobuf:"bytes,3,opt,name=SubType,proto3" json:"SubType"`
|
||||
Data *anypb.Any `protobuf:"bytes,4,opt,name=Data,proto3" json:"Data"`
|
||||
}
|
||||
|
||||
func (x *BatchMessageReq) Reset() {
|
||||
@ -507,9 +507,9 @@ type BroadCastMessageReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
MainType string `protobuf:"bytes,1,opt,name=MainType,proto3" json:"MainType,omitempty"` //服务名
|
||||
SubType string `protobuf:"bytes,2,opt,name=SubType,proto3" json:"SubType,omitempty"`
|
||||
Data *anypb.Any `protobuf:"bytes,3,opt,name=Data,proto3" json:"Data,omitempty"`
|
||||
MainType string `protobuf:"bytes,1,opt,name=MainType,proto3" json:"MainType"` //服务名
|
||||
SubType string `protobuf:"bytes,2,opt,name=SubType,proto3" json:"SubType"`
|
||||
Data *anypb.Any `protobuf:"bytes,3,opt,name=Data,proto3" json:"Data"`
|
||||
}
|
||||
|
||||
func (x *BroadCastMessageReq) Reset() {
|
||||
@ -571,7 +571,7 @@ type AgentCloseeReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
UserSessionId string `protobuf:"bytes,1,opt,name=UserSessionId,proto3" json:"UserSessionId,omitempty"`
|
||||
UserSessionId string `protobuf:"bytes,1,opt,name=UserSessionId,proto3" json:"UserSessionId"`
|
||||
}
|
||||
|
||||
func (x *AgentCloseeReq) Reset() {
|
||||
|
@ -20,19 +20,19 @@ const (
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
type Cache_FriendData struct {
|
||||
type DB_FriendData struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
UserId string `protobuf:"bytes,1,opt,name=userId,proto3" json:"userId,omitempty" bson:"_id"` // ID
|
||||
FriendIds []string `protobuf:"bytes,2,rep,name=friendIds,proto3" json:"friendIds,omitempty"` //好友ID
|
||||
ApplyIds []string `protobuf:"bytes,3,rep,name=applyIds,proto3" json:"applyIds,omitempty"` //申请用户ID
|
||||
BlackIds []string `protobuf:"bytes,4,rep,name=blackIds,proto3" json:"blackIds,omitempty"` //黑名单ID
|
||||
UserId string `protobuf:"bytes,1,opt,name=userId,proto3" json:"userId" bson:"_id"` // ID
|
||||
FriendIds []string `protobuf:"bytes,2,rep,name=friendIds,proto3" json:"friendIds"` //好友ID
|
||||
ApplyIds []string `protobuf:"bytes,3,rep,name=applyIds,proto3" json:"applyIds"` //申请用户ID
|
||||
BlackIds []string `protobuf:"bytes,4,rep,name=blackIds,proto3" json:"blackIds"` //黑名单ID
|
||||
}
|
||||
|
||||
func (x *Cache_FriendData) Reset() {
|
||||
*x = Cache_FriendData{}
|
||||
func (x *DB_FriendData) Reset() {
|
||||
*x = DB_FriendData{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_friend_friend_db_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
@ -40,13 +40,13 @@ func (x *Cache_FriendData) Reset() {
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Cache_FriendData) String() string {
|
||||
func (x *DB_FriendData) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Cache_FriendData) ProtoMessage() {}
|
||||
func (*DB_FriendData) ProtoMessage() {}
|
||||
|
||||
func (x *Cache_FriendData) ProtoReflect() protoreflect.Message {
|
||||
func (x *DB_FriendData) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_friend_friend_db_proto_msgTypes[0]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
@ -58,33 +58,33 @@ func (x *Cache_FriendData) ProtoReflect() protoreflect.Message {
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use Cache_FriendData.ProtoReflect.Descriptor instead.
|
||||
func (*Cache_FriendData) Descriptor() ([]byte, []int) {
|
||||
// Deprecated: Use DB_FriendData.ProtoReflect.Descriptor instead.
|
||||
func (*DB_FriendData) Descriptor() ([]byte, []int) {
|
||||
return file_friend_friend_db_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *Cache_FriendData) GetUserId() string {
|
||||
func (x *DB_FriendData) GetUserId() string {
|
||||
if x != nil {
|
||||
return x.UserId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Cache_FriendData) GetFriendIds() []string {
|
||||
func (x *DB_FriendData) GetFriendIds() []string {
|
||||
if x != nil {
|
||||
return x.FriendIds
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *Cache_FriendData) GetApplyIds() []string {
|
||||
func (x *DB_FriendData) GetApplyIds() []string {
|
||||
if x != nil {
|
||||
return x.ApplyIds
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *Cache_FriendData) GetBlackIds() []string {
|
||||
func (x *DB_FriendData) GetBlackIds() []string {
|
||||
if x != nil {
|
||||
return x.BlackIds
|
||||
}
|
||||
@ -95,16 +95,16 @@ var File_friend_friend_db_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_friend_friend_db_proto_rawDesc = []byte{
|
||||
0x0a, 0x16, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x2f, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x5f,
|
||||
0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x80, 0x01, 0x0a, 0x10, 0x43, 0x61, 0x63,
|
||||
0x68, 0x65, 0x5f, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x44, 0x61, 0x74, 0x61, 0x12, 0x16, 0x0a,
|
||||
0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75,
|
||||
0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49,
|
||||
0x64, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x09, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64,
|
||||
0x49, 0x64, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x49, 0x64, 0x73, 0x18,
|
||||
0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x49, 0x64, 0x73, 0x12,
|
||||
0x1a, 0x0a, 0x08, 0x62, 0x6c, 0x61, 0x63, 0x6b, 0x49, 0x64, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28,
|
||||
0x09, 0x52, 0x08, 0x62, 0x6c, 0x61, 0x63, 0x6b, 0x49, 0x64, 0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e,
|
||||
0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x7d, 0x0a, 0x0d, 0x44, 0x42, 0x5f, 0x46,
|
||||
0x72, 0x69, 0x65, 0x6e, 0x64, 0x44, 0x61, 0x74, 0x61, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65,
|
||||
0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49,
|
||||
0x64, 0x12, 0x1c, 0x0a, 0x09, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x73, 0x18, 0x02,
|
||||
0x20, 0x03, 0x28, 0x09, 0x52, 0x09, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x64, 0x73, 0x12,
|
||||
0x1a, 0x0a, 0x08, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x49, 0x64, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28,
|
||||
0x09, 0x52, 0x08, 0x61, 0x70, 0x70, 0x6c, 0x79, 0x49, 0x64, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x62,
|
||||
0x6c, 0x61, 0x63, 0x6b, 0x49, 0x64, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x62,
|
||||
0x6c, 0x61, 0x63, 0x6b, 0x49, 0x64, 0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62,
|
||||
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
@ -121,7 +121,7 @@ func file_friend_friend_db_proto_rawDescGZIP() []byte {
|
||||
|
||||
var file_friend_friend_db_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
|
||||
var file_friend_friend_db_proto_goTypes = []interface{}{
|
||||
(*Cache_FriendData)(nil), // 0: Cache_FriendData
|
||||
(*DB_FriendData)(nil), // 0: DB_FriendData
|
||||
}
|
||||
var file_friend_friend_db_proto_depIdxs = []int32{
|
||||
0, // [0:0] is the sub-list for method output_type
|
||||
@ -138,7 +138,7 @@ func file_friend_friend_db_proto_init() {
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_friend_friend_db_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Cache_FriendData); i {
|
||||
switch v := v.(*DB_FriendData); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
|
@ -25,13 +25,13 @@ type FriendBase struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
UserId string `protobuf:"bytes,1,opt,name=userId,proto3" json:"userId,omitempty"` //ID
|
||||
NickName string `protobuf:"bytes,2,opt,name=NickName,proto3" json:"NickName,omitempty"` //昵称
|
||||
Level int32 `protobuf:"varint,3,opt,name=level,proto3" json:"level,omitempty"` //等级
|
||||
Avatar int32 `protobuf:"varint,4,opt,name=avatar,proto3" json:"avatar,omitempty"` //头像
|
||||
Strength int64 `protobuf:"varint,5,opt,name=strength,proto3" json:"strength,omitempty"` //战力
|
||||
ServerId int32 `protobuf:"varint,6,opt,name=serverId,proto3" json:"serverId,omitempty"` //服务编号
|
||||
OfflineTime int64 `protobuf:"varint,7,opt,name=offlineTime,proto3" json:"offlineTime,omitempty"` //最近一次下线时间 0在线
|
||||
UserId string `protobuf:"bytes,1,opt,name=userId,proto3" json:"userId"` //ID
|
||||
NickName string `protobuf:"bytes,2,opt,name=NickName,proto3" json:"NickName"` //昵称
|
||||
Level int32 `protobuf:"varint,3,opt,name=level,proto3" json:"level"` //等级
|
||||
Avatar int32 `protobuf:"varint,4,opt,name=avatar,proto3" json:"avatar"` //头像
|
||||
Strength int64 `protobuf:"varint,5,opt,name=strength,proto3" json:"strength"` //战力
|
||||
ServerId int32 `protobuf:"varint,6,opt,name=serverId,proto3" json:"serverId"` //服务编号
|
||||
OfflineTime int64 `protobuf:"varint,7,opt,name=offlineTime,proto3" json:"offlineTime"` //最近一次下线时间 0在线
|
||||
}
|
||||
|
||||
func (x *FriendBase) Reset() {
|
||||
@ -159,7 +159,7 @@ type FriendListRsp struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
List []*FriendBase `protobuf:"bytes,1,rep,name=list,proto3" json:"list,omitempty"`
|
||||
List []*FriendBase `protobuf:"bytes,1,rep,name=list,proto3" json:"list"`
|
||||
}
|
||||
|
||||
func (x *FriendListRsp) Reset() {
|
||||
@ -207,7 +207,7 @@ type FriendApplyReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"` //好友ID
|
||||
FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId"` //好友ID
|
||||
}
|
||||
|
||||
func (x *FriendApplyReq) Reset() {
|
||||
@ -254,8 +254,8 @@ type FriendApplyRsp struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
UserId string `protobuf:"bytes,1,opt,name=userId,proto3" json:"userId,omitempty"` //用户ID
|
||||
FriendId string `protobuf:"bytes,2,opt,name=friendId,proto3" json:"friendId,omitempty"` //好友ID
|
||||
UserId string `protobuf:"bytes,1,opt,name=userId,proto3" json:"userId"` //用户ID
|
||||
FriendId string `protobuf:"bytes,2,opt,name=friendId,proto3" json:"friendId"` //好友ID
|
||||
}
|
||||
|
||||
func (x *FriendApplyRsp) Reset() {
|
||||
@ -310,7 +310,7 @@ type FriendDelReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"` //好友ID
|
||||
FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId"` //好友ID
|
||||
}
|
||||
|
||||
func (x *FriendDelReq) Reset() {
|
||||
@ -357,8 +357,8 @@ type FriendDelRsp struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"` //好友ID
|
||||
UserId string `protobuf:"bytes,2,opt,name=userId,proto3" json:"userId,omitempty"` //用户ID
|
||||
FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId"` //好友ID
|
||||
UserId string `protobuf:"bytes,2,opt,name=userId,proto3" json:"userId"` //用户ID
|
||||
}
|
||||
|
||||
func (x *FriendDelRsp) Reset() {
|
||||
@ -413,7 +413,7 @@ type FriendAgreeReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
FriendIds []string `protobuf:"bytes,1,rep,name=friendIds,proto3" json:"friendIds,omitempty"` //被同意的用户
|
||||
FriendIds []string `protobuf:"bytes,1,rep,name=friendIds,proto3" json:"friendIds"` //被同意的用户
|
||||
}
|
||||
|
||||
func (x *FriendAgreeReq) Reset() {
|
||||
@ -460,7 +460,7 @@ type FriendAgreeRsp struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Num int32 `protobuf:"varint,1,opt,name=Num,proto3" json:"Num,omitempty"` //操作的数量
|
||||
Num int32 `protobuf:"varint,1,opt,name=Num,proto3" json:"Num"` //操作的数量
|
||||
}
|
||||
|
||||
func (x *FriendAgreeRsp) Reset() {
|
||||
@ -508,7 +508,7 @@ type FriendRefuseReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
FriendIds []string `protobuf:"bytes,1,rep,name=friendIds,proto3" json:"friendIds,omitempty"` //被拒绝的用户
|
||||
FriendIds []string `protobuf:"bytes,1,rep,name=friendIds,proto3" json:"friendIds"` //被拒绝的用户
|
||||
}
|
||||
|
||||
func (x *FriendRefuseReq) Reset() {
|
||||
@ -555,7 +555,7 @@ type FriendRefuseRsp struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Num int32 `protobuf:"varint,1,opt,name=Num,proto3" json:"Num,omitempty"` //操作的数量
|
||||
Num int32 `protobuf:"varint,1,opt,name=Num,proto3" json:"Num"` //操作的数量
|
||||
}
|
||||
|
||||
func (x *FriendRefuseRsp) Reset() {
|
||||
@ -641,7 +641,7 @@ type FriendApplyListRsp struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
List []*FriendBase `protobuf:"bytes,1,rep,name=list,proto3" json:"list,omitempty"`
|
||||
List []*FriendBase `protobuf:"bytes,1,rep,name=list,proto3" json:"list"`
|
||||
}
|
||||
|
||||
func (x *FriendApplyListRsp) Reset() {
|
||||
@ -689,7 +689,7 @@ type FriendSearchReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
NickName string `protobuf:"bytes,1,opt,name=nickName,proto3" json:"nickName,omitempty"` //好友昵称
|
||||
NickName string `protobuf:"bytes,1,opt,name=nickName,proto3" json:"nickName"` //好友昵称
|
||||
}
|
||||
|
||||
func (x *FriendSearchReq) Reset() {
|
||||
@ -736,7 +736,7 @@ type FriendSearchRsp struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Friend *FriendBase `protobuf:"bytes,1,opt,name=friend,proto3" json:"friend,omitempty"`
|
||||
Friend *FriendBase `protobuf:"bytes,1,opt,name=friend,proto3" json:"friend"`
|
||||
}
|
||||
|
||||
func (x *FriendSearchRsp) Reset() {
|
||||
@ -822,7 +822,7 @@ type FriendBlackListRsp struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Friends []*FriendBase `protobuf:"bytes,1,rep,name=friends,proto3" json:"friends,omitempty"`
|
||||
Friends []*FriendBase `protobuf:"bytes,1,rep,name=friends,proto3" json:"friends"`
|
||||
}
|
||||
|
||||
func (x *FriendBlackListRsp) Reset() {
|
||||
@ -870,7 +870,7 @@ type FriendBlackAddReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"`
|
||||
FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId"`
|
||||
}
|
||||
|
||||
func (x *FriendBlackAddReq) Reset() {
|
||||
@ -917,8 +917,8 @@ type FriendBlackAddRsp struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"`
|
||||
UserId string `protobuf:"bytes,2,opt,name=userId,proto3" json:"userId,omitempty"`
|
||||
FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId"`
|
||||
UserId string `protobuf:"bytes,2,opt,name=userId,proto3" json:"userId"`
|
||||
}
|
||||
|
||||
func (x *FriendBlackAddRsp) Reset() {
|
||||
@ -973,7 +973,7 @@ type FriendDelBlackReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"`
|
||||
FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId"`
|
||||
}
|
||||
|
||||
func (x *FriendDelBlackReq) Reset() {
|
||||
@ -1020,8 +1020,8 @@ type FriendDelBlackRsp struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"`
|
||||
UserId string `protobuf:"bytes,2,opt,name=userId,proto3" json:"userId,omitempty"`
|
||||
FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId"`
|
||||
UserId string `protobuf:"bytes,2,opt,name=userId,proto3" json:"userId"`
|
||||
}
|
||||
|
||||
func (x *FriendDelBlackRsp) Reset() {
|
||||
@ -1076,7 +1076,7 @@ type FriendReceiveReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"`
|
||||
FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId"`
|
||||
}
|
||||
|
||||
func (x *FriendReceiveReq) Reset() {
|
||||
@ -1123,8 +1123,8 @@ type FriendReceiveRsp struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"`
|
||||
UserId string `protobuf:"bytes,2,opt,name=userId,proto3" json:"userId,omitempty"`
|
||||
FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId"`
|
||||
UserId string `protobuf:"bytes,2,opt,name=userId,proto3" json:"userId"`
|
||||
}
|
||||
|
||||
func (x *FriendReceiveRsp) Reset() {
|
||||
@ -1179,7 +1179,7 @@ type FriendGiveReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"`
|
||||
FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId"`
|
||||
}
|
||||
|
||||
func (x *FriendGiveReq) Reset() {
|
||||
@ -1226,8 +1226,8 @@ type FriendGiveRsp struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"`
|
||||
UserId string `protobuf:"bytes,2,opt,name=userId,proto3" json:"userId,omitempty"`
|
||||
FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId"`
|
||||
UserId string `protobuf:"bytes,2,opt,name=userId,proto3" json:"userId"`
|
||||
}
|
||||
|
||||
func (x *FriendGiveRsp) Reset() {
|
||||
@ -1282,7 +1282,7 @@ type FriendTotalReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"`
|
||||
FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId"`
|
||||
}
|
||||
|
||||
func (x *FriendTotalReq) Reset() {
|
||||
@ -1329,8 +1329,8 @@ type FriendTotalRsp struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId,omitempty"`
|
||||
Total int32 `protobuf:"varint,2,opt,name=total,proto3" json:"total,omitempty"` //好友数量
|
||||
FriendId string `protobuf:"bytes,1,opt,name=friendId,proto3" json:"friendId"`
|
||||
Total int32 `protobuf:"varint,2,opt,name=total,proto3" json:"total"` //好友数量
|
||||
}
|
||||
|
||||
func (x *FriendTotalRsp) Reset() {
|
||||
|
@ -25,8 +25,8 @@ type MailAttachment struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
ItemId uint32 `protobuf:"varint,1,opt,name=ItemId,proto3" json:"ItemId,omitempty"` // 道具iD
|
||||
ItemCount uint32 `protobuf:"varint,2,opt,name=ItemCount,proto3" json:"ItemCount,omitempty"` // 数量
|
||||
ItemId uint32 `protobuf:"varint,1,opt,name=ItemId,proto3" json:"ItemId"` // 道具iD
|
||||
ItemCount uint32 `protobuf:"varint,2,opt,name=ItemCount,proto3" json:"ItemCount"` // 数量
|
||||
}
|
||||
|
||||
func (x *MailAttachment) Reset() {
|
||||
@ -80,15 +80,15 @@ type DB_MailData struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
ObjId string `protobuf:"bytes,1,opt,name=ObjId,proto3" json:"ObjId,omitempty" bson:"_id"` // ID
|
||||
UserId string `protobuf:"bytes,2,opt,name=UserId,proto3" json:"UserId,omitempty"`
|
||||
Title string `protobuf:"bytes,3,opt,name=Title,proto3" json:"Title,omitempty"` // 邮件标题
|
||||
Contex string `protobuf:"bytes,4,opt,name=Contex,proto3" json:"Contex,omitempty"` // 邮件内容
|
||||
CreateTime uint64 `protobuf:"varint,5,opt,name=CreateTime,proto3" json:"CreateTime,omitempty"` // 发送时间
|
||||
DueTime uint64 `protobuf:"varint,6,opt,name=DueTime,proto3" json:"DueTime,omitempty"` // 过期时间
|
||||
Check bool `protobuf:"varint,7,opt,name=Check,proto3" json:"Check,omitempty"` // 是否查看
|
||||
Reward bool `protobuf:"varint,8,opt,name=Reward,proto3" json:"Reward,omitempty"` // 附件领取状态
|
||||
Items []*MailAttachment `protobuf:"bytes,9,rep,name=Items,proto3" json:"Items,omitempty"` // 附件
|
||||
ObjId string `protobuf:"bytes,1,opt,name=ObjId,proto3" json:"ObjId" bson:"_id"` // ID
|
||||
UserId string `protobuf:"bytes,2,opt,name=UserId,proto3" json:"UserId"`
|
||||
Title string `protobuf:"bytes,3,opt,name=Title,proto3" json:"Title"` // 邮件标题
|
||||
Contex string `protobuf:"bytes,4,opt,name=Contex,proto3" json:"Contex"` // 邮件内容
|
||||
CreateTime uint64 `protobuf:"varint,5,opt,name=CreateTime,proto3" json:"CreateTime"` // 发送时间
|
||||
DueTime uint64 `protobuf:"varint,6,opt,name=DueTime,proto3" json:"DueTime"` // 过期时间
|
||||
Check bool `protobuf:"varint,7,opt,name=Check,proto3" json:"Check"` // 是否查看
|
||||
Reward bool `protobuf:"varint,8,opt,name=Reward,proto3" json:"Reward"` // 附件领取状态
|
||||
Items []*MailAttachment `protobuf:"bytes,9,rep,name=Items,proto3" json:"Items"` // 附件
|
||||
}
|
||||
|
||||
func (x *DB_MailData) Reset() {
|
||||
|
@ -64,7 +64,7 @@ type QueryUserMailResp struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Mails []*DB_MailData `protobuf:"bytes,1,rep,name=Mails,proto3" json:"Mails,omitempty"`
|
||||
Mails []*DB_MailData `protobuf:"bytes,1,rep,name=Mails,proto3" json:"Mails"`
|
||||
}
|
||||
|
||||
func (x *QueryUserMailResp) Reset() {
|
||||
@ -112,7 +112,7 @@ type ReadUserMailReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
ObjID string `protobuf:"bytes,1,opt,name=ObjID,proto3" json:"ObjID,omitempty"`
|
||||
ObjID string `protobuf:"bytes,1,opt,name=ObjID,proto3" json:"ObjID"`
|
||||
}
|
||||
|
||||
func (x *ReadUserMailReq) Reset() {
|
||||
@ -159,7 +159,7 @@ type ReadUserMailResp struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Mail *DB_MailData `protobuf:"bytes,1,opt,name=Mail,proto3" json:"Mail,omitempty"`
|
||||
Mail *DB_MailData `protobuf:"bytes,1,opt,name=Mail,proto3" json:"Mail"`
|
||||
}
|
||||
|
||||
func (x *ReadUserMailResp) Reset() {
|
||||
@ -207,7 +207,7 @@ type GetUserMailAttachmentReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
ObjID string `protobuf:"bytes,1,opt,name=ObjID,proto3" json:"ObjID,omitempty"`
|
||||
ObjID string `protobuf:"bytes,1,opt,name=ObjID,proto3" json:"ObjID"`
|
||||
}
|
||||
|
||||
func (x *GetUserMailAttachmentReq) Reset() {
|
||||
@ -254,7 +254,7 @@ type GetUserMailAttachmentResp struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Mail *DB_MailData `protobuf:"bytes,1,opt,name=Mail,proto3" json:"Mail,omitempty"`
|
||||
Mail *DB_MailData `protobuf:"bytes,1,opt,name=Mail,proto3" json:"Mail"`
|
||||
}
|
||||
|
||||
func (x *GetUserMailAttachmentResp) Reset() {
|
||||
@ -302,7 +302,7 @@ type DelUserMailReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
ObjID string `protobuf:"bytes,1,opt,name=ObjID,proto3" json:"ObjID,omitempty"`
|
||||
ObjID string `protobuf:"bytes,1,opt,name=ObjID,proto3" json:"ObjID"`
|
||||
}
|
||||
|
||||
func (x *DelUserMailReq) Reset() {
|
||||
@ -349,7 +349,7 @@ type DelUserMailResp struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Mail []*DB_MailData `protobuf:"bytes,1,rep,name=Mail,proto3" json:"Mail,omitempty"`
|
||||
Mail []*DB_MailData `protobuf:"bytes,1,rep,name=Mail,proto3" json:"Mail"`
|
||||
}
|
||||
|
||||
func (x *DelUserMailResp) Reset() {
|
||||
|
@ -26,14 +26,14 @@ type DB_UserItemData struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
GridId string `protobuf:"bytes,1,opt,name=GridId,proto3" json:"GridId,omitempty"` //背包格子Id
|
||||
UId string `protobuf:"bytes,2,opt,name=UId,proto3" json:"UId,omitempty"` //用户id
|
||||
IsEmpty bool `protobuf:"varint,3,opt,name=IsEmpty,proto3" json:"IsEmpty,omitempty"` //是否是空格子
|
||||
ItemId int32 `protobuf:"varint,4,opt,name=ItemId,proto3" json:"ItemId,omitempty"` //存放物品的Id
|
||||
Amount uint32 `protobuf:"varint,5,opt,name=Amount,proto3" json:"Amount,omitempty"` //存放物品的数量
|
||||
CTime int64 `protobuf:"varint,6,opt,name=CTime,proto3" json:"CTime,omitempty"` //物品获取时间
|
||||
ETime int64 `protobuf:"varint,7,opt,name=ETime,proto3" json:"ETime,omitempty"` //物品过期时间
|
||||
IsNewItem bool `protobuf:"varint,8,opt,name=IsNewItem,proto3" json:"IsNewItem,omitempty"` //是否是新的
|
||||
GridId string `protobuf:"bytes,1,opt,name=GridId,proto3" json:"GridId"` //背包格子Id
|
||||
UId string `protobuf:"bytes,2,opt,name=UId,proto3" json:"UId"` //用户id
|
||||
IsEmpty bool `protobuf:"varint,3,opt,name=IsEmpty,proto3" json:"IsEmpty"` //是否是空格子
|
||||
ItemId int32 `protobuf:"varint,4,opt,name=ItemId,proto3" json:"ItemId"` //存放物品的Id
|
||||
Amount uint32 `protobuf:"varint,5,opt,name=Amount,proto3" json:"Amount"` //存放物品的数量
|
||||
CTime int64 `protobuf:"varint,6,opt,name=CTime,proto3" json:"CTime"` //物品获取时间
|
||||
ETime int64 `protobuf:"varint,7,opt,name=ETime,proto3" json:"ETime"` //物品过期时间
|
||||
IsNewItem bool `protobuf:"varint,8,opt,name=IsNewItem,proto3" json:"IsNewItem"` //是否是新的
|
||||
}
|
||||
|
||||
func (x *DB_UserItemData) Reset() {
|
||||
|
@ -26,7 +26,7 @@ type GetlistReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
IType int32 `protobuf:"varint,1,opt,name=IType,proto3" json:"IType,omitempty"` //道具类型
|
||||
IType int32 `protobuf:"varint,1,opt,name=IType,proto3" json:"IType"` //道具类型
|
||||
}
|
||||
|
||||
func (x *GetlistReq) Reset() {
|
||||
@ -74,7 +74,7 @@ type GetlistResp struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Grids []*DB_UserItemData `protobuf:"bytes,1,rep,name=Grids,proto3" json:"Grids,omitempty"` //用户背包列表
|
||||
Grids []*DB_UserItemData `protobuf:"bytes,1,rep,name=Grids,proto3" json:"Grids"` //用户背包列表
|
||||
}
|
||||
|
||||
func (x *GetlistResp) Reset() {
|
||||
@ -122,9 +122,9 @@ type UseItemReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
GridId int32 `protobuf:"varint,1,opt,name=GridId,proto3" json:"GridId,omitempty"` //格子Id
|
||||
ItemId int32 `protobuf:"varint,2,opt,name=ItemId,proto3" json:"ItemId,omitempty"` //物品Id
|
||||
Amount uint32 `protobuf:"varint,3,opt,name=Amount,proto3" json:"Amount,omitempty"` //使用数量
|
||||
GridId int32 `protobuf:"varint,1,opt,name=GridId,proto3" json:"GridId"` //格子Id
|
||||
ItemId int32 `protobuf:"varint,2,opt,name=ItemId,proto3" json:"ItemId"` //物品Id
|
||||
Amount uint32 `protobuf:"varint,3,opt,name=Amount,proto3" json:"Amount"` //使用数量
|
||||
}
|
||||
|
||||
func (x *UseItemReq) Reset() {
|
||||
@ -225,9 +225,9 @@ type SellItemReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
GridId int32 `protobuf:"varint,1,opt,name=GridId,proto3" json:"GridId,omitempty"` //格子Id
|
||||
ItemId int32 `protobuf:"varint,2,opt,name=ItemId,proto3" json:"ItemId,omitempty"` //物品Id
|
||||
Amount uint32 `protobuf:"varint,3,opt,name=Amount,proto3" json:"Amount,omitempty"` //使用数量
|
||||
GridId int32 `protobuf:"varint,1,opt,name=GridId,proto3" json:"GridId"` //格子Id
|
||||
ItemId int32 `protobuf:"varint,2,opt,name=ItemId,proto3" json:"ItemId"` //物品Id
|
||||
Amount uint32 `protobuf:"varint,3,opt,name=Amount,proto3" json:"Amount"` //使用数量
|
||||
}
|
||||
|
||||
func (x *SellItemReq) Reset() {
|
||||
|
@ -2,7 +2,7 @@ syntax = "proto3";
|
||||
option go_package = ".;pb";
|
||||
|
||||
|
||||
message Cache_FriendData {
|
||||
message DB_FriendData {
|
||||
string userId = 1;// @go_tags(`bson:"_id"`) ID
|
||||
repeated string friendIds = 2; //好友ID
|
||||
repeated string applyIds = 3;//申请用户ID
|
||||
|
@ -5,31 +5,23 @@ import "user/user_db.proto";
|
||||
|
||||
//用户登录
|
||||
message UserLoginReq {
|
||||
string sec= 1;//密文
|
||||
string sec = 1; //密文
|
||||
}
|
||||
|
||||
message UserLoginResp {
|
||||
Cache_UserData data = 1;
|
||||
message UserLoginResp { Cache_UserData data = 1; }
|
||||
|
||||
message UserRegisterReq { string account = 1; }
|
||||
|
||||
message UserRegisterRsp {
|
||||
ErrorCode Code = 1;
|
||||
string account = 2;
|
||||
}
|
||||
|
||||
|
||||
message UserRegisterReq{
|
||||
string account = 1;
|
||||
}
|
||||
|
||||
message UserRegisterRsp{
|
||||
ErrorCode Code = 1;
|
||||
}
|
||||
|
||||
message UserLoadRsp {
|
||||
Cache_UserData data = 1;
|
||||
}
|
||||
message UserLoadRsp { Cache_UserData data = 1; }
|
||||
|
||||
//创角
|
||||
message UserCreateReq{
|
||||
string NickName = 1;//昵称
|
||||
message UserCreateReq {
|
||||
string NickName = 1; //昵称
|
||||
}
|
||||
|
||||
message UserCreateRsp{
|
||||
|
||||
}
|
||||
message UserCreateRsp {}
|
@ -25,9 +25,9 @@ type Cache_UserData struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid,omitempty"`
|
||||
SessionId string `protobuf:"bytes,2,opt,name=SessionId,proto3" json:"SessionId,omitempty"`
|
||||
GatewayServiceId string `protobuf:"bytes,3,opt,name=GatewayServiceId,proto3" json:"GatewayServiceId,omitempty"` // DB_UserData UserData = 4;
|
||||
Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid"`
|
||||
SessionId string `protobuf:"bytes,2,opt,name=SessionId,proto3" json:"SessionId"`
|
||||
GatewayServiceId string `protobuf:"bytes,3,opt,name=GatewayServiceId,proto3" json:"GatewayServiceId"` // DB_UserData UserData = 4;
|
||||
}
|
||||
|
||||
func (x *Cache_UserData) Reset() {
|
||||
@ -88,18 +88,18 @@ type DB_UserData struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty" bson:"_id"` // ID
|
||||
Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid,omitempty"`
|
||||
Uuid string `protobuf:"bytes,3,opt,name=uuid,proto3" json:"uuid,omitempty"` //玩家唯一uuid
|
||||
Binduid string `protobuf:"bytes,4,opt,name=binduid,proto3" json:"binduid,omitempty"` //玩家账号
|
||||
Name string `protobuf:"bytes,5,opt,name=name,proto3" json:"name,omitempty"` //玩家名
|
||||
Sid int32 `protobuf:"varint,6,opt,name=sid,proto3" json:"sid,omitempty"` //区服id
|
||||
Createip string `protobuf:"bytes,7,opt,name=createip,proto3" json:"createip,omitempty"` //创建账号时的ip
|
||||
Lastloginip string `protobuf:"bytes,8,opt,name=lastloginip,proto3" json:"lastloginip,omitempty"` //最后一次登录时的ip
|
||||
Ctime int64 `protobuf:"varint,9,opt,name=ctime,proto3" json:"ctime,omitempty"` //玩家创号时间戳
|
||||
Logintime int64 `protobuf:"varint,10,opt,name=logintime,proto3" json:"logintime,omitempty"` //最后一次登录时间
|
||||
FriendPoint int32 `protobuf:"varint,11,opt,name=FriendPoint,proto3" json:"FriendPoint,omitempty"` //友情点
|
||||
Avatar int32 `protobuf:"varint,12,opt,name=avatar,proto3" json:"avatar,omitempty"` //头像
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` // ID
|
||||
Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid"`
|
||||
Uuid string `protobuf:"bytes,3,opt,name=uuid,proto3" json:"uuid"` //玩家唯一uuid
|
||||
Binduid string `protobuf:"bytes,4,opt,name=binduid,proto3" json:"binduid"` //玩家账号
|
||||
Name string `protobuf:"bytes,5,opt,name=name,proto3" json:"name"` //玩家名
|
||||
Sid int32 `protobuf:"varint,6,opt,name=sid,proto3" json:"sid"` //区服id
|
||||
Createip string `protobuf:"bytes,7,opt,name=createip,proto3" json:"createip"` //创建账号时的ip
|
||||
Lastloginip string `protobuf:"bytes,8,opt,name=lastloginip,proto3" json:"lastloginip"` //最后一次登录时的ip
|
||||
Ctime int64 `protobuf:"varint,9,opt,name=ctime,proto3" json:"ctime"` //玩家创号时间戳
|
||||
Logintime int64 `protobuf:"varint,10,opt,name=logintime,proto3" json:"logintime"` //最后一次登录时间
|
||||
FriendPoint int32 `protobuf:"varint,11,opt,name=FriendPoint,proto3" json:"FriendPoint"` //友情点
|
||||
Avatar int32 `protobuf:"varint,12,opt,name=avatar,proto3" json:"avatar"` //头像
|
||||
}
|
||||
|
||||
func (x *DB_UserData) Reset() {
|
||||
|
@ -26,7 +26,7 @@ type UserLoginReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Sec string `protobuf:"bytes,1,opt,name=sec,proto3" json:"sec,omitempty"` //密文
|
||||
Sec string `protobuf:"bytes,1,opt,name=sec,proto3" json:"sec"` //密文
|
||||
}
|
||||
|
||||
func (x *UserLoginReq) Reset() {
|
||||
@ -73,7 +73,7 @@ type UserLoginResp struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Data *Cache_UserData `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"`
|
||||
Data *Cache_UserData `protobuf:"bytes,1,opt,name=data,proto3" json:"data"`
|
||||
}
|
||||
|
||||
func (x *UserLoginResp) Reset() {
|
||||
@ -120,7 +120,7 @@ type UserRegisterReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Account string `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"`
|
||||
Account string `protobuf:"bytes,1,opt,name=account,proto3" json:"account"`
|
||||
}
|
||||
|
||||
func (x *UserRegisterReq) Reset() {
|
||||
@ -167,7 +167,8 @@ type UserRegisterRsp struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Code ErrorCode `protobuf:"varint,1,opt,name=Code,proto3,enum=ErrorCode" json:"Code,omitempty"`
|
||||
Code ErrorCode `protobuf:"varint,1,opt,name=Code,proto3,enum=ErrorCode" json:"Code"`
|
||||
Account string `protobuf:"bytes,2,opt,name=account,proto3" json:"account"`
|
||||
}
|
||||
|
||||
func (x *UserRegisterRsp) Reset() {
|
||||
@ -209,12 +210,19 @@ func (x *UserRegisterRsp) GetCode() ErrorCode {
|
||||
return ErrorCode_Success
|
||||
}
|
||||
|
||||
func (x *UserRegisterRsp) GetAccount() string {
|
||||
if x != nil {
|
||||
return x.Account
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type UserLoadRsp struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Data *Cache_UserData `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"`
|
||||
Data *Cache_UserData `protobuf:"bytes,1,opt,name=data,proto3" json:"data"`
|
||||
}
|
||||
|
||||
func (x *UserLoadRsp) Reset() {
|
||||
@ -262,7 +270,7 @@ type UserCreateReq struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
NickName string `protobuf:"bytes,1,opt,name=NickName,proto3" json:"NickName,omitempty"` //昵称
|
||||
NickName string `protobuf:"bytes,1,opt,name=NickName,proto3" json:"NickName"` //昵称
|
||||
}
|
||||
|
||||
func (x *UserCreateReq) Reset() {
|
||||
@ -357,18 +365,19 @@ var file_user_user_msg_proto_rawDesc = []byte{
|
||||
0x74, 0x61, 0x22, 0x2b, 0x0a, 0x0f, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74,
|
||||
0x65, 0x72, 0x52, 0x65, 0x71, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74,
|
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22,
|
||||
0x31, 0x0a, 0x0f, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x52,
|
||||
0x4b, 0x0a, 0x0f, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x52,
|
||||
0x73, 0x70, 0x12, 0x1e, 0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e,
|
||||
0x32, 0x0a, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x43, 0x6f,
|
||||
0x64, 0x65, 0x22, 0x32, 0x0a, 0x0b, 0x55, 0x73, 0x65, 0x72, 0x4c, 0x6f, 0x61, 0x64, 0x52, 0x73,
|
||||
0x70, 0x12, 0x23, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32,
|
||||
0x0f, 0x2e, 0x43, 0x61, 0x63, 0x68, 0x65, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61,
|
||||
0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x2b, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x43, 0x72,
|
||||
0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x4e, 0x69, 0x63, 0x6b, 0x4e,
|
||||
0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4e, 0x69, 0x63, 0x6b, 0x4e,
|
||||
0x61, 0x6d, 0x65, 0x22, 0x0f, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x43, 0x72, 0x65, 0x61, 0x74,
|
||||
0x65, 0x52, 0x73, 0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x33,
|
||||
0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20,
|
||||
0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x32, 0x0a, 0x0b,
|
||||
0x55, 0x73, 0x65, 0x72, 0x4c, 0x6f, 0x61, 0x64, 0x52, 0x73, 0x70, 0x12, 0x23, 0x0a, 0x04, 0x64,
|
||||
0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x43, 0x61, 0x63, 0x68,
|
||||
0x65, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61,
|
||||
0x22, 0x2b, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65,
|
||||
0x71, 0x12, 0x1a, 0x0a, 0x08, 0x4e, 0x69, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20,
|
||||
0x01, 0x28, 0x09, 0x52, 0x08, 0x4e, 0x69, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x0f, 0x0a,
|
||||
0x0d, 0x55, 0x73, 0x65, 0x72, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x73, 0x70, 0x42, 0x06,
|
||||
0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
|
67
services/dbservice/main.go
Normal file
67
services/dbservice/main.go
Normal file
@ -0,0 +1,67 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"go_dreamfactory/modules/dbservice"
|
||||
"go_dreamfactory/services"
|
||||
"go_dreamfactory/sys/cache"
|
||||
"go_dreamfactory/sys/db"
|
||||
|
||||
"go_dreamfactory/lego"
|
||||
"go_dreamfactory/lego/base/rpcx"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
)
|
||||
|
||||
/*
|
||||
服务类型:dbservice
|
||||
服务描述:处理梦工厂的具体业务需求,包含 user,pack,mail,friend...功能业务模块
|
||||
*/
|
||||
var (
|
||||
conf = flag.String("conf", "./conf/dbservice.yaml", "获取需要启动的服务配置文件") //启动服务的Id
|
||||
)
|
||||
|
||||
/*服务启动的入口函数*/
|
||||
func main() {
|
||||
flag.Parse()
|
||||
s := NewService(
|
||||
rpcx.SetConfPath(*conf),
|
||||
rpcx.SetVersion("1.0.0.0"),
|
||||
)
|
||||
s.OnInstallComp( //装备组件
|
||||
//services.NewGateRouteComp(), //此服务需要接受用户的消息 需要装备网关组件
|
||||
)
|
||||
lego.Run(s, //运行模块
|
||||
dbservice.NewModule(),
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
func NewService(ops ...rpcx.Option) core.IService {
|
||||
s := new(Service)
|
||||
s.Configure(ops...)
|
||||
return s
|
||||
}
|
||||
|
||||
//worker 的服务对象定义
|
||||
type Service struct {
|
||||
services.ServiceBase
|
||||
}
|
||||
|
||||
//初始化worker需要的一些系统工具
|
||||
func (this *Service) InitSys() {
|
||||
this.ServiceBase.InitSys()
|
||||
//缓存系统
|
||||
if err := cache.OnInit(this.GetSettings().Sys["cache"]); err != nil {
|
||||
panic(fmt.Sprintf("init sys.cache err: %s", err.Error()))
|
||||
} else {
|
||||
log.Infof("init sys.cache success!")
|
||||
}
|
||||
//存储系统
|
||||
if err := db.OnInit(this.GetSettings().Sys["db"]); err != nil {
|
||||
panic(fmt.Sprintf("init sys.db err: %s", err.Error()))
|
||||
} else {
|
||||
log.Infof("init sys.db success!")
|
||||
}
|
||||
}
|
3
sys/cache/core.go
vendored
3
sys/cache/core.go
vendored
@ -9,9 +9,6 @@ redis 缓存数据管理系统
|
||||
type (
|
||||
ISys interface {
|
||||
Redis() redis.ISys
|
||||
IUser //户模块的相关缓存接口
|
||||
IFriend //好友相关的缓存接口
|
||||
|
||||
}
|
||||
)
|
||||
|
||||
|
59
sys/cache/friend.go
vendored
59
sys/cache/friend.go
vendored
@ -1,59 +0,0 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go_dreamfactory/lego/sys/redis"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/db"
|
||||
)
|
||||
|
||||
const ( //Redis
|
||||
Redis_FriendCache string = "friend:%s"
|
||||
Redis_Friend string = "apply:%s"
|
||||
)
|
||||
|
||||
func getRdsFriendKey(userId string) string {
|
||||
return fmt.Sprintf(Redis_FriendCache, userId)
|
||||
}
|
||||
|
||||
type IFriend interface {
|
||||
Friend_Update(data *pb.Cache_FriendData) (err error)
|
||||
Friend_Total(userId string) int32
|
||||
Friend_Get(userId string) (*pb.Cache_FriendData, error)
|
||||
}
|
||||
|
||||
//更新
|
||||
func (this *Cache) Friend_Update(data *pb.Cache_FriendData) (err error) {
|
||||
if err = db.Defsys.Friend_SaveOrUpdate(data); err == nil {
|
||||
//更新缓存
|
||||
err = this.redis.Set(getRdsFriendKey(data.UserId), data, 0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//好友总数
|
||||
func (this *Cache) Friend_Total(userId string) int32 {
|
||||
var friend *pb.Cache_FriendData
|
||||
err := this.redis.Get(getRdsFriendKey(userId), &friend)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
return int32(len(friend.FriendIds))
|
||||
}
|
||||
|
||||
//好友获取
|
||||
func (this *Cache) Friend_Get(userId string) (*pb.Cache_FriendData, error) {
|
||||
var d *pb.Cache_FriendData
|
||||
err := this.redis.Get(getRdsFriendKey(userId), &d)
|
||||
if err != nil {
|
||||
if err.Error() == string(redis.RedisNil) {
|
||||
d = &pb.Cache_FriendData{UserId: userId}
|
||||
err = this.Friend_Update(d)
|
||||
if err != nil {
|
||||
return d, nil
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return d, nil
|
||||
}
|
31
sys/cache/friend_test.go
vendored
31
sys/cache/friend_test.go
vendored
@ -1,31 +0,0 @@
|
||||
package cache_test
|
||||
|
||||
import (
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/cache"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestFriendApply(t *testing.T) {
|
||||
err := cache.Defsys.Friend_Update(&pb.Cache_FriendData{
|
||||
UserId: "629f159310d6970846f7ef26",
|
||||
FriendIds: []string{"629f147e3d276120561bfa18"},
|
||||
ApplyIds: []string{"629eb3f4132dc4bb26139659"},
|
||||
})
|
||||
|
||||
require.Nil(t, err, nil)
|
||||
}
|
||||
|
||||
func TestFriendGetTotal(t *testing.T) {
|
||||
total := cache.Defsys.Friend_Total("629f159310d6970846f7ef26")
|
||||
assert.Equal(t, total, int32(2))
|
||||
}
|
||||
|
||||
func TestFriendGet(t *testing.T) {
|
||||
data, err := cache.Defsys.Friend_Get("629f159310d6970846f7ef26")
|
||||
require.NotNil(t, err, nil)
|
||||
assert.Equal(t, data.UserId, "629f159310d6970846f7ef26")
|
||||
}
|
65
sys/cache/init_test.go
vendored
65
sys/cache/init_test.go
vendored
@ -8,9 +8,14 @@ import (
|
||||
"go_dreamfactory/sys/cache"
|
||||
"go_dreamfactory/sys/db"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go_dreamfactory/utils"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
@ -38,7 +43,7 @@ func TestMain(m *testing.M) {
|
||||
Reward: false,
|
||||
}
|
||||
//db.InsertModelLogs("mail", "uid123", _mail)
|
||||
//InsertModelLogs("mail", "uid123", _mail)
|
||||
db.Defsys.Mgo().InsertOne("mail", _mail)
|
||||
data := &comm.Autogenerated{
|
||||
ID: primitive.NewObjectID().Hex(),
|
||||
UID: "uid123",
|
||||
@ -52,8 +57,66 @@ func TestMain(m *testing.M) {
|
||||
log.Errorf("insert model db err %v", err1)
|
||||
}
|
||||
//}()
|
||||
|
||||
///////////////////////////////////////
|
||||
filter := bson.M{
|
||||
"userid": "uid123",
|
||||
"title": "系统邮件",
|
||||
}
|
||||
var nd *pb.DB_MailData
|
||||
err := db.Defsys.Mgo().FindOne("mail", filter).Decode(&nd)
|
||||
if err == nil {
|
||||
nd.Check = true
|
||||
nd.Reward = true
|
||||
|
||||
data1 := &comm.Autogenerated{
|
||||
ID: primitive.NewObjectID().Hex(),
|
||||
UID: "uid123",
|
||||
Act: string(comm.LogHandleType_Update),
|
||||
}
|
||||
filter1 := bson.M{
|
||||
"userid": "uid123",
|
||||
"title": "系统邮件",
|
||||
}
|
||||
data1.D = make([]interface{}, 0)
|
||||
data1.D = append(data1.D, "mail") // D[0]
|
||||
data1.D = append(data1.D, &filter1) // D[1]
|
||||
data1.D = append(data1.D, nd) // D[2]
|
||||
|
||||
_, err = db.Defsys.Mgo().InsertOne("model_log", data1)
|
||||
if err != nil {
|
||||
log.Errorf("insert model db err %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
time.Sleep(time.Second * 10)
|
||||
|
||||
defer os.Exit(m.Run())
|
||||
|
||||
}
|
||||
|
||||
func TestSet(t *testing.T) {
|
||||
friendDb := &pb.DB_FriendData{
|
||||
UserId: "111",
|
||||
FriendIds: []string{"222"},
|
||||
ApplyIds: []string{"333"},
|
||||
BlackIds: []string{"444"},
|
||||
}
|
||||
data := utils.Pb2Map(friendDb)
|
||||
// data2 := map[string]interface{}{
|
||||
// "userId": friendDb.UserId,
|
||||
// "friendIds": friendDb.FriendIds,
|
||||
// "applyIds": friendDb.ApplyIds,
|
||||
// "blackIds": friendDb.BlackIds,
|
||||
// }
|
||||
|
||||
cache.Redis().HMSet("friend:222", data)
|
||||
}
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
result, err := cache.Redis().HGetAll("111", reflect.TypeOf(map[string]interface{}{}))
|
||||
require.Nil(t, err)
|
||||
|
||||
fmt.Println(result...)
|
||||
}
|
||||
|
36
sys/cache/user.go
vendored
36
sys/cache/user.go
vendored
@ -1,36 +0,0 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/db"
|
||||
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
)
|
||||
|
||||
const ( //Redis
|
||||
Redis_UserCache string = "user:%s" //会话列表
|
||||
)
|
||||
|
||||
type IUser interface {
|
||||
Update(data *pb.Cache_UserData) (err error)
|
||||
Get(userId string) *pb.Cache_UserData
|
||||
}
|
||||
|
||||
func (this *Cache) Update(data *pb.Cache_UserData) (err error) {
|
||||
err = db.Defsys.User_Update(data.UserData)
|
||||
if err == nil {
|
||||
err = this.redis.Set(fmt.Sprintf(Redis_UserCache, data.UserData.Uid), data, -1)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (this *Cache) Get(userId string) *pb.Cache_UserData {
|
||||
var user *pb.Cache_UserData
|
||||
err := this.redis.Get(fmt.Sprintf(Redis_UserCache, userId), &user)
|
||||
if err != nil {
|
||||
log.Errorf("get user cache err:%v", err)
|
||||
return nil
|
||||
}
|
||||
return user
|
||||
}
|
29
sys/cache/user_test.go
vendored
29
sys/cache/user_test.go
vendored
@ -1,29 +0,0 @@
|
||||
package cache_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/cache"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
func TestUpdateUser(t *testing.T) {
|
||||
user := &pb.Cache_UserData{
|
||||
SessionId: "1",
|
||||
GatewayServiceId: "work",
|
||||
UserData: &pb.DB_UserData{
|
||||
Uid: primitive.NewObjectID().Hex(),
|
||||
Name: "aaa",
|
||||
},
|
||||
}
|
||||
err := cache.Defsys.Update(user)
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
func TestGetUser(t *testing.T) {
|
||||
c := cache.Defsys.Get("62157")
|
||||
fmt.Println(c)
|
||||
}
|
@ -5,8 +5,6 @@ import "go_dreamfactory/lego/sys/mgo"
|
||||
type (
|
||||
ISys interface {
|
||||
Mgo() mgo.ISys
|
||||
IUser
|
||||
IFriend
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -1,70 +0,0 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go_dreamfactory/pb"
|
||||
"time"
|
||||
|
||||
"go_dreamfactory/lego/core"
|
||||
|
||||
uuid "github.com/satori/go.uuid"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
const ( //Redis
|
||||
DB_UserTable core.SqlTable = "user" //用户表
|
||||
)
|
||||
|
||||
type IUser interface {
|
||||
User_FindByAccount(user *pb.DB_UserData) (*pb.DB_UserData, error)
|
||||
User_FindById(id string) (*pb.DB_UserData, error)
|
||||
User_Create(user *pb.DB_UserData) error
|
||||
User_Update(data *pb.DB_UserData) (err error)
|
||||
}
|
||||
|
||||
//
|
||||
func (this *DB) User_FindByAccount(user *pb.DB_UserData) (*pb.DB_UserData, error) {
|
||||
filter := bson.M{
|
||||
"sid": user.Sid,
|
||||
"binduid": user.Binduid,
|
||||
}
|
||||
sr := this.mgo.FindOne(DB_UserTable, filter)
|
||||
var nd *pb.DB_UserData
|
||||
err := sr.Decode(&nd)
|
||||
return nd, err
|
||||
}
|
||||
|
||||
func (this *DB) User_FindById(id string) (*pb.DB_UserData, error) {
|
||||
filter := bson.M{
|
||||
"userid": id,
|
||||
}
|
||||
sr := this.mgo.FindOne(DB_UserTable, filter)
|
||||
user := &pb.DB_UserData{}
|
||||
err := sr.Decode(user)
|
||||
return user, err
|
||||
}
|
||||
|
||||
func (this *DB) User_Create(user *pb.DB_UserData) (err error) {
|
||||
_id := primitive.NewObjectID().Hex()
|
||||
user.Id = _id
|
||||
user.Uid = fmt.Sprintf("%d_%s", user.Sid, _id)
|
||||
user.Uuid = uuid.NewV4().String()
|
||||
user.Ctime = time.Now().Unix()
|
||||
_, err = this.mgo.InsertOne(DB_UserTable, user)
|
||||
return err
|
||||
}
|
||||
|
||||
//更新用户数据到DB
|
||||
func (this *DB) User_Update(data *pb.DB_UserData) (err error) {
|
||||
err = this.mgo.FindOneAndUpdate(
|
||||
DB_UserTable,
|
||||
bson.M{"uid": data.Uid},
|
||||
bson.M{"$set": bson.M{
|
||||
"name": data.Name,
|
||||
}},
|
||||
options.FindOneAndUpdate().SetUpsert(true),
|
||||
).Err()
|
||||
return err
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"go_dreamfactory/pb"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
user := &pb.DB_UserData{
|
||||
Binduid: "legu131",
|
||||
Name: "legu131",
|
||||
Sid: 1,
|
||||
}
|
||||
|
||||
|
||||
|
||||
err := db.User_Create(user)
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
func TestFindOne(t *testing.T) {
|
||||
user, err := db.User_FindById("629eb3f4132dc4bb26139659")
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "legu3", user.Binduid)
|
||||
|
||||
// user.ServerId = 2
|
||||
user2, err := db.User_FindByAccount(user)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, "legu3", user2.Binduid)
|
||||
assert.Equal(t, int32(1), user2.Sid)
|
||||
}
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
user := &pb.DB_UserData{
|
||||
Uuid: primitive.NewObjectID().Hex(),
|
||||
}
|
||||
err := db.User_Update(user)
|
||||
require.Nil(t, err)
|
||||
|
||||
assert.Equal(t, "NiceName", "")
|
||||
}
|
21
utils/pb.go
Normal file
21
utils/pb.go
Normal file
@ -0,0 +1,21 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func Pb2Map(rp interface{}) map[string]interface{} {
|
||||
m := make(map[string]interface{})
|
||||
vals := reflect.ValueOf(rp).Elem()
|
||||
for i := 0; i < vals.NumField(); i++ {
|
||||
valueField := vals.Field(i)
|
||||
typeField := vals.Type().Field(i)
|
||||
|
||||
if valueField.CanInterface() {
|
||||
f := valueField.Interface()
|
||||
// val := reflect.ValueOf(f)
|
||||
m[typeField.Tag.Get("json")] = f //可以根据需要取具体的tag,做相应的处理即可
|
||||
}
|
||||
}
|
||||
return m
|
||||
}
|
Loading…
Reference in New Issue
Block a user