Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into meixiongfeng
This commit is contained in:
commit
0416ce5b17
@ -2,24 +2,79 @@ package robot
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
|
"go_dreamfactory/modules/friend"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *Robot) handleFriendMsg(msg *pb.UserMessage) {
|
func (r *Robot) handleFriendMsg(msg *pb.UserMessage) {
|
||||||
switch msg.SubType {
|
switch msg.SubType {
|
||||||
case "apply":
|
case friend.Friend_SubType_Apply:
|
||||||
r.handleFriendApply(msg)
|
r.handleFriendApply(msg)
|
||||||
|
case friend.Friend_SubType_ApplyList:
|
||||||
|
r.handleFriendApplyList(msg)
|
||||||
|
case friend.Friend_SubType_Agree:
|
||||||
|
r.handleFriendAgree(msg)
|
||||||
|
case friend.Friend_SubType_Refuse:
|
||||||
|
r.handleFriendRefuse(msg)
|
||||||
|
case friend.Friend_SubType_Blacklist:
|
||||||
|
r.handleFriendBlacklist(msg)
|
||||||
|
case friend.Friend_SubType_AddBlack:
|
||||||
|
r.handleFriendAddBlack(msg)
|
||||||
|
case friend.Friend_SubType_DelBlack:
|
||||||
|
r.handleFriendDelBlack(msg)
|
||||||
|
case friend.Friend_SubType_Search:
|
||||||
|
r.handleFriendSearch(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//添加好友
|
//好友列表
|
||||||
|
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)
|
||||||
|
err := r.SendToClient(head, req)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Robot) handleFriendList(msg *pb.UserMessage) {
|
||||||
|
rsp := &pb.FriendListRsp{}
|
||||||
|
if !comm.ProtoDecode(msg, rsp) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
printReply(msg, rsp)
|
||||||
|
}
|
||||||
|
|
||||||
|
//好友搜索
|
||||||
|
func (r *Robot) FriendSearch(nickName string) {
|
||||||
|
req := &pb.FriendSearchReq{
|
||||||
|
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)
|
||||||
|
err := r.SendToClient(head, req)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Robot) handleFriendSearch(msg *pb.UserMessage) {
|
||||||
|
rsp := &pb.FriendSearchRsp{}
|
||||||
|
if !comm.ProtoDecode(msg, rsp) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
printReply(msg, rsp)
|
||||||
|
}
|
||||||
|
|
||||||
|
//好友申请
|
||||||
func (r *Robot) FriendApply(friendId string) {
|
func (r *Robot) FriendApply(friendId string) {
|
||||||
req := &pb.FriendApplyReq{
|
req := &pb.FriendApplyReq{
|
||||||
FriendId: friendId,
|
FriendId: friendId,
|
||||||
}
|
}
|
||||||
head := &pb.UserMessage{MainType: "friend", SubType: "apply"}
|
head := &pb.UserMessage{MainType: string(comm.SM_FriendModule), SubType: friend.Friend_SubType_Apply}
|
||||||
defer traceFunc(head.MainType, head.SubType, r.user.UserData.GetUserId(), req)
|
defer traceFunc(head.MainType, head.SubType, r.user.UserData.GetUid(), req)
|
||||||
err := r.SendToClient(head, req)
|
err := r.SendToClient(head, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@ -33,3 +88,123 @@ func (r *Robot) handleFriendApply(msg *pb.UserMessage) {
|
|||||||
}
|
}
|
||||||
printReply(msg, rsp)
|
printReply(msg, rsp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//申请列表
|
||||||
|
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)
|
||||||
|
err := r.SendToClient(head, req)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Robot) handleFriendApplyList(msg *pb.UserMessage) {
|
||||||
|
rsp := &pb.FriendApplyListRsp{}
|
||||||
|
if !comm.ProtoDecode(msg, rsp) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
printReply(msg, rsp)
|
||||||
|
}
|
||||||
|
|
||||||
|
//同意
|
||||||
|
func (r *Robot) FriendAgree(friendIds []string) {
|
||||||
|
req := &pb.FriendAgreeReq{
|
||||||
|
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)
|
||||||
|
err := r.SendToClient(head, req)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Robot) handleFriendAgree(msg *pb.UserMessage) {
|
||||||
|
rsp := &pb.FriendAgreeRsp{}
|
||||||
|
if !comm.ProtoDecode(msg, rsp) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
printReply(msg, rsp)
|
||||||
|
}
|
||||||
|
|
||||||
|
//拒绝
|
||||||
|
func (r *Robot) FriendRefuse(friendIds []string) {
|
||||||
|
req := &pb.FriendRefuseReq{
|
||||||
|
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)
|
||||||
|
err := r.SendToClient(head, req)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Robot) handleFriendRefuse(msg *pb.UserMessage) {
|
||||||
|
rsp := &pb.FriendRefuseRsp{}
|
||||||
|
if !comm.ProtoDecode(msg, rsp) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
printReply(msg, rsp)
|
||||||
|
}
|
||||||
|
|
||||||
|
//黑名单列表
|
||||||
|
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)
|
||||||
|
err := r.SendToClient(head, req)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Robot) handleFriendBlacklist(msg *pb.UserMessage) {
|
||||||
|
rsp := &pb.FriendBlackListRsp{}
|
||||||
|
if !comm.ProtoDecode(msg, rsp) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
printReply(msg, rsp)
|
||||||
|
}
|
||||||
|
|
||||||
|
//添加黑名单
|
||||||
|
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)
|
||||||
|
err := r.SendToClient(head, req)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Robot) handleFriendAddBlack(msg *pb.UserMessage) {
|
||||||
|
rsp := &pb.FriendBlackAddRsp{}
|
||||||
|
if !comm.ProtoDecode(msg, rsp) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
printReply(msg, rsp)
|
||||||
|
}
|
||||||
|
|
||||||
|
//删除黑名单
|
||||||
|
func (r *Robot) FriendDelBlack(friendId string) {
|
||||||
|
req := &pb.FriendDelBlackReq{
|
||||||
|
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)
|
||||||
|
err := r.SendToClient(head, req)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Robot) handleFriendDelBlack(msg *pb.UserMessage) {
|
||||||
|
rsp := &pb.FriendDelBlackRsp{}
|
||||||
|
if !comm.ProtoDecode(msg, rsp) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
printReply(msg, rsp)
|
||||||
|
}
|
||||||
|
@ -17,7 +17,7 @@ func (r *Robot) handlePackMsg(msg *pb.UserMessage) {
|
|||||||
func (r *Robot) QueryUserPack() {
|
func (r *Robot) QueryUserPack() {
|
||||||
req := &pb.GetlistReq{IType: 1}
|
req := &pb.GetlistReq{IType: 1}
|
||||||
head := &pb.UserMessage{MainType: "pack", SubType: "queryuserpackreq"}
|
head := &pb.UserMessage{MainType: "pack", SubType: "queryuserpackreq"}
|
||||||
defer traceFunc(head.MainType, head.SubType, r.user.UserData.GetUserId(), req)
|
defer traceFunc(head.MainType, head.SubType, r.user.UserData.GetUid(), req)
|
||||||
err := r.SendToClient(head, req)
|
err := r.SendToClient(head, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -9,9 +9,9 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/golang/protobuf/proto"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
"google.golang.org/protobuf/proto"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Robot struct {
|
type Robot struct {
|
||||||
@ -79,13 +79,21 @@ func (r *Robot) handleMsg(msg *pb.UserMessage) {
|
|||||||
//在这里添加玩家成功登录以后的测试方法
|
//在这里添加玩家成功登录以后的测试方法
|
||||||
func (r *Robot) onUserLoaded() {
|
func (r *Robot) onUserLoaded() {
|
||||||
//user
|
//user
|
||||||
r.CreateUser("user671")
|
// r.CreateUser("乐谷4")
|
||||||
|
|
||||||
//friend
|
//friend
|
||||||
r.FriendApply("629f147e3d276120561bfa18")
|
// r.FriendApply("629f147e3d276120561bfa18")
|
||||||
|
// r.FriendAgree([]string{})
|
||||||
|
// r.FriendRefuse([]string{})
|
||||||
|
// r.FriendApplyList()
|
||||||
|
// r.FriendList()
|
||||||
|
// r.FriendBlacklist()
|
||||||
|
// r.FriendAddBlack()
|
||||||
|
// r.FriendDelBlack("")
|
||||||
|
r.FriendSearch("乐谷5")
|
||||||
|
|
||||||
//pack
|
//pack
|
||||||
r.QueryUserPack()
|
// r.QueryUserPack()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,10 +145,12 @@ func (r *Robot) AccountRegister() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//打印响应
|
||||||
func printReply(msg *pb.UserMessage, rsp interface{}) {
|
func printReply(msg *pb.UserMessage, rsp interface{}) {
|
||||||
log.Printf("rsp [%s.%s] [%d] [%v]", msg.MainType, msg.SubType, msg.Code, rsp)
|
log.Printf("rsp [%s.%s] [%d] [%v]", msg.MainType, msg.SubType, msg.Code, rsp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//方法参数跟踪
|
||||||
func traceFunc(module string, funcName string, uid string, funcArgs interface{}) {
|
func traceFunc(module string, funcName string, uid string, funcArgs interface{}) {
|
||||||
log.Printf("req [%s.%s] [%s] [%v]", module, funcName, uid, funcArgs)
|
log.Printf("req [%s.%s] [%s] [%v]", module, funcName, uid, funcArgs)
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package robot
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
|
"go_dreamfactory/modules/user"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
@ -40,11 +41,11 @@ func (r *Robot) CreateUser(NickName string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
head := &pb.UserMessage{
|
head := &pb.UserMessage{
|
||||||
MainType: "user",
|
MainType: string(comm.SM_UserModule),
|
||||||
SubType: "create",
|
SubType: user.User_SubType_Create,
|
||||||
}
|
}
|
||||||
|
|
||||||
defer traceFunc(head.MainType, head.SubType, r.user.UserData.GetUserId(), req)
|
defer traceFunc(head.MainType, head.SubType, r.user.UserData.GetUid(), req)
|
||||||
err := r.SendToClient(head, req)
|
err := r.SendToClient(head, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
16
comm/core.go
16
comm/core.go
@ -7,13 +7,19 @@ import (
|
|||||||
"go_dreamfactory/lego/core"
|
"go_dreamfactory/lego/core"
|
||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
|
|
||||||
"google.golang.org/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
|
"github.com/golang/protobuf/ptypes"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SC_ServiceGateRouteComp core.S_Comps = "SC_GateRouteComp" //s_comps.ISC_GateRouteComp
|
SC_ServiceGateRouteComp core.S_Comps = "SC_GateRouteComp" //s_comps.ISC_GateRouteComp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
Service_Gateway = "gateway"
|
||||||
|
Service_Worker = "worker"
|
||||||
|
)
|
||||||
|
|
||||||
//模块名定义处
|
//模块名定义处
|
||||||
const (
|
const (
|
||||||
SM_GateModule core.M_Modules = "gateway" //gate模块 网关服务模块
|
SM_GateModule core.M_Modules = "gateway" //gate模块 网关服务模块
|
||||||
@ -55,15 +61,15 @@ type IUserSession interface {
|
|||||||
GetIP() string
|
GetIP() string
|
||||||
GetGatewayServiceId() string
|
GetGatewayServiceId() string
|
||||||
IsLogin() bool
|
IsLogin() bool
|
||||||
Build(uid string) (err error)
|
Bind(uid string, wokerId string) (err error)
|
||||||
UnBuild(ServiceMethod string, msg proto.Message) (err error)
|
UnBind() (err error)
|
||||||
SendMsg(mainType, subType string, code pb.ErrorCode, msg proto.Message) (err error)
|
SendMsg(mainType, subType string, code pb.ErrorCode, msg proto.Message) (err error)
|
||||||
Close() (err error)
|
Close() (err error)
|
||||||
ToString() string
|
ToString() string
|
||||||
}
|
}
|
||||||
|
|
||||||
func ProtoDecode(msg *pb.UserMessage, req proto.Message) (ok bool) {
|
func ProtoDecode(msg *pb.UserMessage, req proto.Message) (ok bool) {
|
||||||
err := proto.Unmarshal(msg.Data, req)
|
err := ptypes.UnmarshalAny(msg.Data, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("%s.%s %v", msg.MainType, msg.SubType, err)
|
log.Errorf("%s.%s %v", msg.MainType, msg.SubType, err)
|
||||||
return
|
return
|
||||||
@ -72,7 +78,7 @@ func ProtoDecode(msg *pb.UserMessage, req proto.Message) (ok bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ProtoEncode(rsp proto.Message, msg *pb.UserMessage) (ok bool) {
|
func ProtoEncode(rsp proto.Message, msg *pb.UserMessage) (ok bool) {
|
||||||
data, err := proto.Marshal(rsp)
|
data, err := ptypes.MarshalAny(rsp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("%s.%s %v", msg.MainType, msg.SubType, err)
|
log.Errorf("%s.%s %v", msg.MainType, msg.SubType, err)
|
||||||
return
|
return
|
||||||
|
@ -11,6 +11,10 @@ type (
|
|||||||
}
|
}
|
||||||
//背包模块对外接口定义 提供给其他模块使用的
|
//背包模块对外接口定义 提供给其他模块使用的
|
||||||
IPack interface {
|
IPack interface {
|
||||||
|
//查询用户背包物品数量
|
||||||
|
QueryUserPackItemAmount(uId string, itemid int32) (amount uint32)
|
||||||
|
///添加单个物品到背包 (可以加物品和减物品)
|
||||||
|
AddItemToUserPack(uId string, itemid, addnum int32) (err error)
|
||||||
///添加多个物品到背包 (可以加物品和减物品)
|
///添加多个物品到背包 (可以加物品和减物品)
|
||||||
AddItemsToUserPack(uId string, items map[int32]int32) (err error)
|
AddItemsToUserPack(uId string, items map[int32]int32) (err error)
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,8 @@ import (
|
|||||||
"go_dreamfactory/lego/base"
|
"go_dreamfactory/lego/base"
|
||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
|
|
||||||
"google.golang.org/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
|
"github.com/golang/protobuf/ptypes"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -58,25 +59,27 @@ func (this *UserSession) IsLogin() bool {
|
|||||||
return this.UserId != ""
|
return this.UserId != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
//绑定uid 登录后操作
|
///绑定uid 登录后操作
|
||||||
func (this *UserSession) Build(uid string) (err error) {
|
///uid 用户id
|
||||||
|
///wokerId 用户绑定worker服务id
|
||||||
|
func (this *UserSession) Bind(uid string, wokerId string) (err error) {
|
||||||
reply := &pb.RPCMessageReply{}
|
reply := &pb.RPCMessageReply{}
|
||||||
if err := this.service.RpcCallById(this.GatewayServiceId, string(Rpc_GatewayAgentBuild), context.Background(), &pb.AgentBuildReq{
|
if err := this.service.RpcCall(context.Background(), fmt.Sprintf("%s/%s", Service_Gateway, this.GatewayServiceId), string(Rpc_GatewayAgentBuild), &pb.AgentBuildReq{
|
||||||
UserSessionId: this.SessionId,
|
UserSessionId: this.SessionId,
|
||||||
UserId: uid,
|
UserId: uid,
|
||||||
}, reply); err != nil {
|
}, reply); err != nil {
|
||||||
log.Errorf("UserSession:%s UserId:%s Build:%s err:%v", this.SessionId, this.UserId, err)
|
log.Errorf("Bind UserSession:%s UserId:%s err:%v", this.SessionId, this.UserId, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//解绑uid 注销和切换账号是处理
|
//解绑uid 注销和切换账号是处理
|
||||||
func (this *UserSession) UnBuild(ServiceMethod string, msg proto.Message) (err error) {
|
func (this *UserSession) UnBind() (err error) {
|
||||||
reply := &pb.RPCMessageReply{}
|
reply := &pb.RPCMessageReply{}
|
||||||
if err := this.service.RpcCallById(this.GatewayServiceId, string(Rpc_GatewayAgentUnBuild), context.Background(), &pb.AgentUnBuildReq{
|
if err := this.service.RpcCall(context.Background(), fmt.Sprintf("%s/%s", Service_Gateway, this.GatewayServiceId), string(Rpc_GatewayAgentUnBuild), &pb.AgentUnBuildReq{
|
||||||
UserSessionId: this.SessionId,
|
UserSessionId: this.SessionId,
|
||||||
}, reply); err != nil {
|
}, reply); err != nil {
|
||||||
log.Errorf("UserSession:%s UserId:%s UnBuild err:%v", this.SessionId, this.UserId, err)
|
log.Errorf("UnBuild UserSession:%s UserId:%s err:%v", this.SessionId, this.UserId, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -84,16 +87,16 @@ func (this *UserSession) UnBuild(ServiceMethod string, msg proto.Message) (err e
|
|||||||
//向用户发送消息
|
//向用户发送消息
|
||||||
func (this *UserSession) SendMsg(mainType, subType string, code pb.ErrorCode, msg proto.Message) (err error) {
|
func (this *UserSession) SendMsg(mainType, subType string, code pb.ErrorCode, msg proto.Message) (err error) {
|
||||||
reply := &pb.RPCMessageReply{}
|
reply := &pb.RPCMessageReply{}
|
||||||
data, _ := proto.Marshal(msg)
|
data, _ := ptypes.MarshalAny(msg)
|
||||||
log.Debugf("SendMsg to SessionId:[%s] UserId:[%s] Code:%d Data: %v", this.UserId, code, msg)
|
log.Debugf("SendMsg to SessionId:[%s] UserId:[%s] Code:%d Data: %v", this.UserId, code, msg)
|
||||||
if err := this.service.RpcCallById(this.GatewayServiceId, string(Rpc_GatewayAgentSendMsg), context.Background(), &pb.AgentSendMessageReq{
|
if err := this.service.RpcCall(context.Background(), fmt.Sprintf("%s/%s", Service_Gateway, this.GatewayServiceId), string(Rpc_GatewayAgentSendMsg), &pb.AgentSendMessageReq{
|
||||||
UserSessionId: this.SessionId,
|
UserSessionId: this.SessionId,
|
||||||
MainType: mainType,
|
MainType: mainType,
|
||||||
SubType: subType,
|
SubType: subType,
|
||||||
Code: code,
|
Code: code,
|
||||||
Data: data,
|
Data: data,
|
||||||
}, reply); err != nil {
|
}, reply); err != nil {
|
||||||
log.Errorf("UserSession:%s UserId:%s SendMsg:%s err:%v", this.SessionId, this.UserId, mainType, err)
|
log.Errorf("SendMsg:%s UserSession:%s UserId:%s err:%v", mainType, this.SessionId, this.UserId, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -101,10 +104,10 @@ func (this *UserSession) SendMsg(mainType, subType string, code pb.ErrorCode, ms
|
|||||||
//关闭用户连接对象
|
//关闭用户连接对象
|
||||||
func (this *UserSession) Close() (err error) {
|
func (this *UserSession) Close() (err error) {
|
||||||
reply := &pb.RPCMessageReply{}
|
reply := &pb.RPCMessageReply{}
|
||||||
if err := this.service.RpcCallById(this.GatewayServiceId, string(Rpc_GatewayAgentSendMsg), context.Background(), &pb.AgentCloseeReq{
|
if err := this.service.RpcCall(context.Background(), fmt.Sprintf("%s/%s", Service_Gateway, this.GatewayServiceId), string(Rpc_GatewayAgentSendMsg), &pb.AgentCloseeReq{
|
||||||
UserSessionId: this.SessionId,
|
UserSessionId: this.SessionId,
|
||||||
}, reply); err != nil {
|
}, reply); err != nil {
|
||||||
log.Errorf("UserSession:%s UserId:%d Close:%s err:%v", this.SessionId, this.UserId, err)
|
log.Errorf("Close UserSession:%s UserId:%d err:%v", this.SessionId, this.UserId, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
4
go.mod
4
go.mod
@ -7,12 +7,14 @@ require (
|
|||||||
github.com/go-playground/validator/v10 v10.10.1
|
github.com/go-playground/validator/v10 v10.10.1
|
||||||
github.com/go-redis/redis/v8 v8.11.5
|
github.com/go-redis/redis/v8 v8.11.5
|
||||||
github.com/golang-jwt/jwt v3.2.2+incompatible
|
github.com/golang-jwt/jwt v3.2.2+incompatible
|
||||||
|
github.com/golang/protobuf v1.5.2
|
||||||
github.com/gorilla/websocket v1.4.2
|
github.com/gorilla/websocket v1.4.2
|
||||||
github.com/hashicorp/consul/api v1.12.0
|
github.com/hashicorp/consul/api v1.12.0
|
||||||
github.com/json-iterator/go v1.1.12
|
github.com/json-iterator/go v1.1.12
|
||||||
github.com/mitchellh/hashstructure v1.1.0
|
github.com/mitchellh/hashstructure v1.1.0
|
||||||
github.com/nacos-group/nacos-sdk-go v1.0.8
|
github.com/nacos-group/nacos-sdk-go v1.0.8
|
||||||
github.com/natefinch/lumberjack v2.0.0+incompatible
|
github.com/natefinch/lumberjack v2.0.0+incompatible
|
||||||
|
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475
|
||||||
github.com/robfig/cron/v3 v3.0.1
|
github.com/robfig/cron/v3 v3.0.1
|
||||||
github.com/rs/xid v1.3.0
|
github.com/rs/xid v1.3.0
|
||||||
github.com/satori/go.uuid v1.2.0
|
github.com/satori/go.uuid v1.2.0
|
||||||
@ -53,6 +55,7 @@ require (
|
|||||||
github.com/go-ping/ping v0.0.0-20211130115550-779d1e919534 // indirect
|
github.com/go-ping/ping v0.0.0-20211130115550-779d1e919534 // indirect
|
||||||
github.com/go-playground/locales v0.14.0 // indirect
|
github.com/go-playground/locales v0.14.0 // indirect
|
||||||
github.com/go-playground/universal-translator v0.18.0 // indirect
|
github.com/go-playground/universal-translator v0.18.0 // indirect
|
||||||
|
github.com/go-redis/redis_rate/v9 v9.1.2 // indirect
|
||||||
github.com/go-stack/stack v1.8.0 // indirect
|
github.com/go-stack/stack v1.8.0 // indirect
|
||||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
|
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
|
||||||
github.com/gogo/protobuf v1.3.2 // indirect
|
github.com/gogo/protobuf v1.3.2 // indirect
|
||||||
@ -68,6 +71,7 @@ require (
|
|||||||
github.com/hashicorp/golang-lru v0.5.4 // indirect
|
github.com/hashicorp/golang-lru v0.5.4 // indirect
|
||||||
github.com/hashicorp/serf v0.9.7 // indirect
|
github.com/hashicorp/serf v0.9.7 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||||
|
github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c // indirect
|
||||||
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
||||||
github.com/juju/ratelimit v1.0.1 // indirect
|
github.com/juju/ratelimit v1.0.1 // indirect
|
||||||
github.com/julienschmidt/httprouter v1.3.0 // indirect
|
github.com/julienschmidt/httprouter v1.3.0 // indirect
|
||||||
|
3
go.sum
3
go.sum
@ -170,6 +170,7 @@ github.com/go-redis/redis/v8 v8.8.2/go.mod h1:F7resOH5Kdug49Otu24RjHWwgK7u9AmtqW
|
|||||||
github.com/go-redis/redis/v8 v8.11.4/go.mod h1:2Z2wHZXdQpCDXEGzqMockDpNyYvi2l4Pxt6RJr792+w=
|
github.com/go-redis/redis/v8 v8.11.4/go.mod h1:2Z2wHZXdQpCDXEGzqMockDpNyYvi2l4Pxt6RJr792+w=
|
||||||
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
|
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
|
||||||
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
|
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
|
||||||
|
github.com/go-redis/redis_rate/v9 v9.1.2 h1:H0l5VzoAtOE6ydd38j8MCq3ABlGLnvvbA1xDSVVCHgQ=
|
||||||
github.com/go-redis/redis_rate/v9 v9.1.2/go.mod h1:oam2de2apSgRG8aJzwJddXbNu91Iyz1m8IKJE2vpvlQ=
|
github.com/go-redis/redis_rate/v9 v9.1.2/go.mod h1:oam2de2apSgRG8aJzwJddXbNu91Iyz1m8IKJE2vpvlQ=
|
||||||
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||||
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
|
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
|
||||||
@ -359,6 +360,7 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
|
|||||||
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||||
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
||||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||||
|
github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c h1:qSHzRbhzK8RdXOsAdfDgO49TtqC1oZ+acxPrkfTxcCs=
|
||||||
github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
|
github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
|
||||||
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 h1:IPJ3dvxmJ4uczJe5YQdrYB16oTJlGSC/OyZDqUk9xX4=
|
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 h1:IPJ3dvxmJ4uczJe5YQdrYB16oTJlGSC/OyZDqUk9xX4=
|
||||||
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869/go.mod h1:cJ6Cj7dQo+O6GJNiMx+Pa94qKj+TG8ONdKHgMNIyyag=
|
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869/go.mod h1:cJ6Cj7dQo+O6GJNiMx+Pa94qKj+TG8ONdKHgMNIyyag=
|
||||||
@ -548,6 +550,7 @@ github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R
|
|||||||
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||||
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
||||||
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
|
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
|
||||||
|
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM=
|
||||||
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
||||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
||||||
|
@ -74,12 +74,9 @@ type IRPCXServiceSession interface {
|
|||||||
|
|
||||||
type IRPCXService interface {
|
type IRPCXService interface {
|
||||||
IClusterServiceBase
|
IClusterServiceBase
|
||||||
DefauleRpcRouteRules(stype string, sip string) (ss IRPCXServiceSession, err error) //默认rpc路由规则
|
|
||||||
Register(rcvr interface{}) (err error)
|
Register(rcvr interface{}) (err error)
|
||||||
RegisterFunction(fn interface{}) (err error)
|
RegisterFunction(fn interface{}) (err error)
|
||||||
RegisterFunctionName(name string, fn interface{}) (err error)
|
RegisterFunctionName(name string, fn interface{}) (err error)
|
||||||
RpcCallById(sId string, serviceMethod string, ctx context.Context, args interface{}, reply interface{}) (err error)
|
RpcCall(ctx context.Context, servicePath string, serviceMethod string, args interface{}, reply interface{}) (err error)
|
||||||
RpcGoById(sId string, serviceMethod string, ctx context.Context, args interface{}, reply interface{}) (call *client.Call, err error)
|
RpcGo(ctx context.Context, servicePath string, serviceMethod string, args interface{}, reply interface{}) (call *client.Call, err error)
|
||||||
RpcCallByType(sType string, serviceMethod string, ctx context.Context, args interface{}, reply interface{}) (err error)
|
|
||||||
RpcGoByType(sType string, serviceMethod string, ctx context.Context, args interface{}, reply interface{}) (call *client.Call, err error)
|
|
||||||
}
|
}
|
||||||
|
@ -4,29 +4,22 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"go_dreamfactory/lego"
|
|
||||||
"go_dreamfactory/lego/base"
|
"go_dreamfactory/lego/base"
|
||||||
"go_dreamfactory/lego/core"
|
"go_dreamfactory/lego/core"
|
||||||
"go_dreamfactory/lego/core/cbase"
|
"go_dreamfactory/lego/core/cbase"
|
||||||
"go_dreamfactory/lego/sys/cron"
|
"go_dreamfactory/lego/sys/cron"
|
||||||
"go_dreamfactory/lego/sys/event"
|
"go_dreamfactory/lego/sys/event"
|
||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
"go_dreamfactory/lego/sys/registry"
|
|
||||||
"go_dreamfactory/lego/sys/rpcx"
|
"go_dreamfactory/lego/sys/rpcx"
|
||||||
"go_dreamfactory/lego/utils/container/sortslice"
|
|
||||||
"go_dreamfactory/lego/utils/container/version"
|
|
||||||
|
|
||||||
"github.com/smallnest/rpcx/client"
|
"github.com/smallnest/rpcx/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RPCXService struct {
|
type RPCXService struct {
|
||||||
cbase.ServiceBase //继承服务基类
|
cbase.ServiceBase //继承服务基类+
|
||||||
opts *Options //服务启动的配置信息数据
|
opts *Options //服务启动的配置信息数据
|
||||||
serverList sync.Map //集群服务会话管理列表对象
|
|
||||||
rpcxService base.IRPCXService //服务自身 通过接口可以实现上层服务类重构底层接口
|
rpcxService base.IRPCXService //服务自身 通过接口可以实现上层服务类重构底层接口
|
||||||
IsInClustered bool //当前服务是否已加入到集群中
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RPCXService) GetTag() string {
|
func (this *RPCXService) GetTag() string {
|
||||||
@ -89,12 +82,7 @@ func (this *RPCXService) InitSys() {
|
|||||||
} else {
|
} else {
|
||||||
log.Infof("Sys event Init success !")
|
log.Infof("Sys event Init success !")
|
||||||
}
|
}
|
||||||
if err := registry.OnInit(this.opts.Setting.Sys["registry"], registry.SetService(this.rpcxService), registry.SetListener(this.rpcxService.(registry.IListener))); err != nil {
|
if err := rpcx.OnInit(this.opts.Setting.Sys["rpcx"], rpcx.SetServiceTag(this.GetTag()), rpcx.SetServiceId(this.GetId()), rpcx.SetServiceType(this.GetType()), rpcx.SetServiceVersion(this.GetVersion()), rpcx.SetServiceAddr(fmt.Sprintf("%s:%d", this.GetIp(), this.GetPort()))); err != nil {
|
||||||
log.Panicf(fmt.Sprintf("Sys registry Init err:%v", err))
|
|
||||||
} else {
|
|
||||||
log.Infof("Sys registry Init success !")
|
|
||||||
}
|
|
||||||
if err := rpcx.OnInit(this.opts.Setting.Sys["rpcx"], rpcx.SetServiceId(this.GetId()), rpcx.SetPort(this.GetPort())); err != nil {
|
|
||||||
log.Panicf(fmt.Sprintf("Sys rpcx Init err:%v", err))
|
log.Panicf(fmt.Sprintf("Sys rpcx Init err:%v", err))
|
||||||
} else {
|
} else {
|
||||||
log.Infof("Sys rpcx Init success !")
|
log.Infof("Sys rpcx Init success !")
|
||||||
@ -103,9 +91,6 @@ func (this *RPCXService) InitSys() {
|
|||||||
if err := rpcx.Start(); err != nil {
|
if err := rpcx.Start(); err != nil {
|
||||||
log.Panicf(fmt.Sprintf("Sys rpcx Start err:%v", err))
|
log.Panicf(fmt.Sprintf("Sys rpcx Start err:%v", err))
|
||||||
}
|
}
|
||||||
if err := registry.Start(); err != nil {
|
|
||||||
log.Panicf(fmt.Sprintf("Sys registry Start err:%v", err))
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,142 +111,11 @@ func (this *RPCXService) Destroy() (err error) {
|
|||||||
if err = rpcx.Stop(); err != nil {
|
if err = rpcx.Stop(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = registry.Stop(); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cron.Stop()
|
cron.Stop()
|
||||||
err = this.ServiceBase.Destroy()
|
err = this.ServiceBase.Destroy()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//注册服务会话 当有新的服务加入时
|
|
||||||
func (this *RPCXService) FindServiceHandlefunc(node registry.ServiceNode) {
|
|
||||||
if _, ok := this.serverList.Load(node.Id); !ok {
|
|
||||||
if s, err := NewServiceSession(&node); err != nil {
|
|
||||||
log.Errorf("创建服务会话失败【%s】 err:%v", node.Id, err)
|
|
||||||
} else {
|
|
||||||
this.serverList.Store(node.Id, s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if this.IsInClustered {
|
|
||||||
event.TriggerEvent(core.Event_FindNewService, node) //触发发现新的服务事件
|
|
||||||
} else {
|
|
||||||
if node.Id == this.opts.Setting.Id { //发现自己 加入集群成功
|
|
||||||
this.IsInClustered = true
|
|
||||||
event.TriggerEvent(core.Event_RegistryStart)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//更新服务会话 当有新的服务加入时
|
|
||||||
func (this *RPCXService) UpDataServiceHandlefunc(node registry.ServiceNode) {
|
|
||||||
if ss, ok := this.serverList.Load(node.Id); ok { //已经在缓存中 需要更新节点信息
|
|
||||||
session := ss.(base.IRPCXServiceSession)
|
|
||||||
if session.GetRpcId() != node.RpcId {
|
|
||||||
if s, err := NewServiceSession(&node); err != nil {
|
|
||||||
log.Errorf("更新服务会话失败【%s】 err:%v", node.Id, err)
|
|
||||||
} else {
|
|
||||||
this.serverList.Store(node.Id, s)
|
|
||||||
}
|
|
||||||
event.TriggerEvent(core.Event_FindNewService, node) //触发发现新的服务事件
|
|
||||||
} else {
|
|
||||||
if session.GetVersion() != node.Version {
|
|
||||||
session.SetVersion(node.Version)
|
|
||||||
}
|
|
||||||
if session.GetPreWeight() != node.PreWeight {
|
|
||||||
session.SetPreWeight(node.PreWeight)
|
|
||||||
}
|
|
||||||
event.TriggerEvent(core.Event_UpDataOldService, node) //触发发现新的服务事件
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//注销服务会话
|
|
||||||
func (this *RPCXService) LoseServiceHandlefunc(sId string) {
|
|
||||||
session, ok := this.serverList.Load(sId)
|
|
||||||
if ok && session != nil {
|
|
||||||
session.(base.IRPCXServiceSession).Done()
|
|
||||||
this.serverList.Delete(sId)
|
|
||||||
}
|
|
||||||
event.TriggerEvent(core.Event_LoseService, sId) //触发发现新的服务事件
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *RPCXService) getServiceSessionByType(sType string, sIp string) (ss []base.IRPCXServiceSession, err error) {
|
|
||||||
ss = make([]base.IRPCXServiceSession, 0)
|
|
||||||
if nodes := registry.GetServiceByType(sType); nodes == nil {
|
|
||||||
log.Errorf("获取目标类型 type【%s】ip [%s] 服务集失败", sType, sIp)
|
|
||||||
return nil, err
|
|
||||||
} else {
|
|
||||||
if sIp == core.AutoIp {
|
|
||||||
for _, v := range nodes {
|
|
||||||
if s, ok := this.serverList.Load(v.Id); ok {
|
|
||||||
ss = append(ss, s.(base.IRPCXServiceSession))
|
|
||||||
} else {
|
|
||||||
s, err = NewServiceSession(v)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("创建服务会话失败【%s】 err:%v", v.Id, err)
|
|
||||||
continue
|
|
||||||
} else {
|
|
||||||
this.serverList.Store(v.Id, s)
|
|
||||||
ss = append(ss, s.(base.IRPCXServiceSession))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for _, v := range nodes {
|
|
||||||
if v.IP == sIp {
|
|
||||||
if s, ok := this.serverList.Load(v.Id); ok {
|
|
||||||
ss = append(ss, s.(base.IRPCXServiceSession))
|
|
||||||
} else {
|
|
||||||
s, err = NewServiceSession(v)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("创建服务会话失败【%s】 err:%v", v.Id, err)
|
|
||||||
continue
|
|
||||||
} else {
|
|
||||||
this.serverList.Store(v.Id, s)
|
|
||||||
ss = append(ss, s.(base.IRPCXServiceSession))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
//默认路由规则
|
|
||||||
func (this *RPCXService) DefauleRpcRouteRules(stype string, sip string) (ss base.IRPCXServiceSession, err error) {
|
|
||||||
if s, e := this.getServiceSessionByType(stype, sip); e != nil {
|
|
||||||
return nil, e
|
|
||||||
} else {
|
|
||||||
ss := make([]interface{}, len(s))
|
|
||||||
for i, v := range s {
|
|
||||||
ss[i] = v
|
|
||||||
}
|
|
||||||
if len(ss) > 0 {
|
|
||||||
//排序找到最优服务
|
|
||||||
sortslice.Sort(ss, func(a interface{}, b interface{}) int8 {
|
|
||||||
as := a.(base.IRPCXServiceSession)
|
|
||||||
bs := b.(base.IRPCXServiceSession)
|
|
||||||
if iscompare := version.CompareStrVer(as.GetVersion(), bs.GetVersion()); iscompare != 0 {
|
|
||||||
return iscompare
|
|
||||||
} else {
|
|
||||||
if as.GetPreWeight() < bs.GetPreWeight() {
|
|
||||||
return 1
|
|
||||||
} else if as.GetPreWeight() > bs.GetPreWeight() {
|
|
||||||
return -1
|
|
||||||
} else {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return ss[0].(base.IRPCXServiceSession), nil
|
|
||||||
} else {
|
|
||||||
return nil, fmt.Errorf("未找到IP[%s]类型%s】的服务信息", sip, stype)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//注册服务对象
|
//注册服务对象
|
||||||
func (this *RPCXService) Register(rcvr interface{}) (err error) {
|
func (this *RPCXService) Register(rcvr interface{}) (err error) {
|
||||||
err = rpcx.Register(rcvr)
|
err = rpcx.Register(rcvr)
|
||||||
@ -281,65 +135,11 @@ func (this *RPCXService) RegisterFunctionName(name string, fn interface{}) (err
|
|||||||
}
|
}
|
||||||
|
|
||||||
//同步 执行目标远程服务方法
|
//同步 执行目标远程服务方法
|
||||||
func (this *RPCXService) RpcCallById(sId string, serviceMethod string, ctx context.Context, args interface{}, reply interface{}) (err error) {
|
func (this *RPCXService) RpcCall(ctx context.Context, servicePath string, serviceMethod string, args interface{}, reply interface{}) (err error) {
|
||||||
defer lego.Recover(fmt.Sprintf("RpcCallById sId:%s rkey:%v arg %v", sId, serviceMethod, args))
|
return rpcx.Call(ctx, servicePath, serviceMethod, args, reply)
|
||||||
ss, ok := this.serverList.Load(sId)
|
|
||||||
if !ok {
|
|
||||||
if node, err := registry.GetServiceById(sId); err != nil {
|
|
||||||
log.Errorf("未找到目标服务【%s】节点 err:%v", sId, err)
|
|
||||||
return fmt.Errorf("No Found " + sId)
|
|
||||||
} else {
|
|
||||||
ss, err = NewServiceSession(node)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf(fmt.Sprintf("创建服务会话失败【%s】 err:%v", sId, err))
|
|
||||||
} else {
|
|
||||||
this.serverList.Store(node.Id, ss)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
err = ss.(base.IRPCXServiceSession).Call(ctx, serviceMethod, args, reply)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//异步 执行目标远程服务方法
|
//异步 执行目标远程服务方法
|
||||||
func (this *RPCXService) RpcGoById(sId string, serviceMethod string, ctx context.Context, args interface{}, reply interface{}) (call *client.Call, err error) {
|
func (this *RPCXService) RpcGo(ctx context.Context, servicePath string, serviceMethod string, args interface{}, reply interface{}) (call *client.Call, err error) {
|
||||||
defer lego.Recover(fmt.Sprintf("RpcGoById sId:%s rkey:%v arg %v", sId, serviceMethod, args))
|
return rpcx.Go(ctx, servicePath, serviceMethod, args, reply, nil)
|
||||||
ss, ok := this.serverList.Load(sId)
|
|
||||||
if !ok {
|
|
||||||
if node, err := registry.GetServiceById(sId); err != nil {
|
|
||||||
log.Errorf("未找到目标服务【%s】节点 err:%v", sId, err)
|
|
||||||
return nil, fmt.Errorf("No Found " + sId)
|
|
||||||
} else {
|
|
||||||
ss, err = NewServiceSession(node)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf(fmt.Sprintf("创建服务会话失败【%s】 err:%v", sId, err))
|
|
||||||
} else {
|
|
||||||
this.serverList.Store(node.Id, ss)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
call, err = ss.(base.IRPCXServiceSession).Go(ctx, serviceMethod, args, reply)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *RPCXService) RpcCallByType(sType string, serviceMethod string, ctx context.Context, args interface{}, reply interface{}) (err error) {
|
|
||||||
defer lego.Recover(fmt.Sprintf("RpcCallByType sType:%s rkey:%s arg %v", sType, serviceMethod, args))
|
|
||||||
ss, err := this.rpcxService.DefauleRpcRouteRules(sType, core.AutoIp)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("未找到目标服务【%s】节点 err:%v", sType, err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = ss.Call(ctx, serviceMethod, args, reply)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *RPCXService) RpcGoByType(sType string, serviceMethod string, ctx context.Context, args interface{}, reply interface{}) (call *client.Call, err error) {
|
|
||||||
defer lego.Recover(fmt.Sprintf("RpcCallByType sType:%s rkey:%s arg %v", sType, serviceMethod, args))
|
|
||||||
ss, err := this.rpcxService.DefauleRpcRouteRules(sType, core.AutoIp)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("未找到目标服务【%s】节点 err:%v", sType, err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
call, err = ss.Go(ctx, serviceMethod, args, reply)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
@ -1,64 +0,0 @@
|
|||||||
package rpcx
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"go_dreamfactory/lego/base"
|
|
||||||
"go_dreamfactory/lego/sys/registry"
|
|
||||||
"go_dreamfactory/lego/sys/rpcx"
|
|
||||||
|
|
||||||
"github.com/smallnest/rpcx/client"
|
|
||||||
)
|
|
||||||
|
|
||||||
func NewServiceSession(node *registry.ServiceNode) (ss base.IRPCXServiceSession, err error) {
|
|
||||||
session := new(ServiceSession)
|
|
||||||
session.node = node
|
|
||||||
session.client, err = rpcx.NewRpcClient(fmt.Sprintf("%s:%d", node.IP, node.Port), node.Id)
|
|
||||||
ss = session
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
type ServiceSession struct {
|
|
||||||
node *registry.ServiceNode
|
|
||||||
client rpcx.IRPCXClient
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *ServiceSession) GetId() string {
|
|
||||||
return this.node.Id
|
|
||||||
}
|
|
||||||
func (this *ServiceSession) GetIp() string {
|
|
||||||
return this.node.IP
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *ServiceSession) GetRpcId() string {
|
|
||||||
return this.node.RpcId
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *ServiceSession) GetType() string {
|
|
||||||
return this.node.Type
|
|
||||||
}
|
|
||||||
func (this *ServiceSession) GetVersion() string {
|
|
||||||
return this.node.Version
|
|
||||||
}
|
|
||||||
func (this *ServiceSession) SetVersion(v string) {
|
|
||||||
this.node.Version = v
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *ServiceSession) GetPreWeight() float64 {
|
|
||||||
return this.node.PreWeight
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *ServiceSession) SetPreWeight(p float64) {
|
|
||||||
this.node.PreWeight = p
|
|
||||||
}
|
|
||||||
func (this *ServiceSession) Done() {
|
|
||||||
this.client.Stop()
|
|
||||||
}
|
|
||||||
func (this *ServiceSession) Call(ctx context.Context, serviceMethod string, args interface{}, reply interface{}) error {
|
|
||||||
return this.client.Call(ctx, serviceMethod, args, reply)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *ServiceSession) Go(ctx context.Context, serviceMethod string, args interface{}, reply interface{}) (*client.Call, error) {
|
|
||||||
return this.client.Go(ctx, serviceMethod, args, reply, nil)
|
|
||||||
}
|
|
@ -2,30 +2,102 @@ package rpcx
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/smallnest/rpcx/client"
|
"github.com/smallnest/rpcx/client"
|
||||||
|
"github.com/smallnest/rpcx/share"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newClient(addr string, sId string) (c *Client, err error) {
|
func newClient(rpcx *RPCX) (c *Client) {
|
||||||
c = &Client{}
|
c = &Client{
|
||||||
d, err := client.NewPeer2PeerDiscovery("tcp@"+addr, "")
|
rpcx: rpcx,
|
||||||
c.xclient = client.NewXClient(sId, client.Failfast, client.RandomSelect, d, client.DefaultOption)
|
clients: make(map[string]client.XClient),
|
||||||
|
// msgChan: make(chan *protocol.Message, 1000),
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
xclient client.XClient
|
rpcx *RPCX
|
||||||
|
clients map[string]client.XClient
|
||||||
|
// msgChan chan *protocol.Message // 接收rpcXServer推送消息
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoMessage 服务端消息处理
|
||||||
|
func (this *Client) DoMessage() {
|
||||||
|
// for msg := range this.msgChan {
|
||||||
|
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Client) Start() (err error) {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Client) Stop() (err error) {
|
func (this *Client) Stop() (err error) {
|
||||||
err = this.xclient.Close()
|
for _, v := range this.clients {
|
||||||
|
v.Close()
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Client) Call(ctx context.Context, serviceMethod string, args interface{}, reply interface{}) (err error) {
|
//同步调用
|
||||||
err = this.xclient.Call(ctx, string(serviceMethod), args, reply)
|
func (this *Client) Call(ctx context.Context, servicePath string, serviceMethod string, args interface{}, reply interface{}) (err error) {
|
||||||
|
if servicePath == "" {
|
||||||
|
err = errors.New("servicePath no cant null")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func (this *Client) Go(ctx context.Context, serviceMethod string, args interface{}, reply interface{}, done chan *client.Call) (*client.Call, error) {
|
var (
|
||||||
return this.xclient.Go(ctx, string(serviceMethod), args, reply, done)
|
spath []string
|
||||||
|
d *client.ConsulDiscovery
|
||||||
|
c client.XClient
|
||||||
|
ok bool
|
||||||
|
)
|
||||||
|
spath = strings.Split(servicePath, "/")
|
||||||
|
if c, ok = this.clients[spath[0]]; !ok {
|
||||||
|
if d, err = client.NewConsulDiscovery(this.rpcx.options.ServiceTag, spath[0], this.rpcx.options.ConsulServers, nil); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c = client.NewXClient(spath[0], client.Failfast, client.RandomSelect, d, client.DefaultOption)
|
||||||
|
c.SetSelector(newSelector())
|
||||||
|
this.clients[spath[0]] = c
|
||||||
|
}
|
||||||
|
ctx = context.WithValue(ctx, share.ReqMetaDataKey, map[string]string{
|
||||||
|
CallRoutRulesKey: servicePath,
|
||||||
|
ServiceAddrKey: "tcp@" + this.rpcx.options.ServiceAddr,
|
||||||
|
ServiceMetaKey: this.rpcx.metadata,
|
||||||
|
})
|
||||||
|
err = c.Call(ctx, serviceMethod, args, reply)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//异步调用
|
||||||
|
func (this *Client) Go(ctx context.Context, servicePath string, serviceMethod string, args interface{}, reply interface{}, done chan *client.Call) (call *client.Call, err error) {
|
||||||
|
// return this.xclient.Go(ctx, string(serviceMethod), args, reply, done)
|
||||||
|
if servicePath == "" {
|
||||||
|
err = errors.New("servicePath no cant null")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var (
|
||||||
|
spath []string
|
||||||
|
d *client.ConsulDiscovery
|
||||||
|
c client.XClient
|
||||||
|
ok bool
|
||||||
|
)
|
||||||
|
spath = strings.Split(servicePath, "/")
|
||||||
|
if c, ok = this.clients[spath[0]]; !ok {
|
||||||
|
if d, err = client.NewConsulDiscovery(this.rpcx.options.ServiceTag, spath[0], this.rpcx.options.ConsulServers, nil); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c = client.NewXClient(spath[0], client.Failfast, client.RandomSelect, d, client.DefaultOption)
|
||||||
|
c.SetSelector(newSelector())
|
||||||
|
this.clients[spath[0]] = c
|
||||||
|
}
|
||||||
|
ctx = context.WithValue(ctx, share.ReqMetaDataKey, map[string]string{
|
||||||
|
CallRoutRulesKey: servicePath,
|
||||||
|
ServiceAddrKey: "tcp@" + this.rpcx.options.ServiceAddr,
|
||||||
|
ServiceMetaKey: this.rpcx.metadata,
|
||||||
|
})
|
||||||
|
return c.Go(ctx, string(serviceMethod), args, reply, done)
|
||||||
}
|
}
|
||||||
|
@ -2,16 +2,23 @@ package rpcx
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
|
||||||
"github.com/smallnest/rpcx/client"
|
"github.com/smallnest/rpcx/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ServiceMetaKey = "smeta"
|
||||||
|
ServiceAddrKey = "addr"
|
||||||
|
CallRoutRulesKey = "callrules"
|
||||||
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
ISys interface {
|
ISys interface {
|
||||||
IRPCXServer
|
IRPCXServer
|
||||||
NewRpcClient(addr, sId string) (clent IRPCXClient, err error)
|
IRPCXClient
|
||||||
}
|
}
|
||||||
|
|
||||||
IRPCXServer interface {
|
IRPCXServer interface {
|
||||||
Start() (err error)
|
Start() (err error)
|
||||||
Stop() (err error)
|
Stop() (err error)
|
||||||
@ -22,9 +29,10 @@ type (
|
|||||||
}
|
}
|
||||||
|
|
||||||
IRPCXClient interface {
|
IRPCXClient interface {
|
||||||
|
Start() (err error)
|
||||||
Stop() (err error)
|
Stop() (err error)
|
||||||
Call(ctx context.Context, serviceMethod string, args interface{}, reply interface{}) error
|
Call(ctx context.Context, servicePath string, serviceMethod string, args interface{}, reply interface{}) (err error)
|
||||||
Go(ctx context.Context, serviceMethod string, args interface{}, reply interface{}, done chan *client.Call) (*client.Call, error)
|
Go(ctx context.Context, servicePath string, serviceMethod string, args interface{}, reply interface{}, done chan *client.Call) (call *client.Call, err error)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -33,12 +41,20 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func OnInit(config map[string]interface{}, option ...Option) (err error) {
|
func OnInit(config map[string]interface{}, option ...Option) (err error) {
|
||||||
defsys, err = newSys(newOptions(config, option...))
|
var options Options
|
||||||
|
if options, err = newOptions(config, option...); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defsys, err = newSys(options)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSys(option ...Option) (sys ISys, err error) {
|
func NewSys(option ...Option) (sys ISys, err error) {
|
||||||
sys, err = newSys(newOptionsByOption(option...))
|
var options Options
|
||||||
|
if options, err = newOptionsByOption(option...); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sys, err = newSys(options)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,6 +80,51 @@ func UnregisterAll() (err error) {
|
|||||||
return defsys.UnregisterAll()
|
return defsys.UnregisterAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRpcClient(addr, sId string) (clent IRPCXClient, err error) {
|
func Call(ctx context.Context, servicePath string, serviceMethod string, args interface{}, reply interface{}) (err error) {
|
||||||
return defsys.NewRpcClient(addr, sId)
|
return defsys.Call(ctx, servicePath, serviceMethod, args, reply)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Go(ctx context.Context, servicePath string, serviceMethod string, args interface{}, reply interface{}, done chan *client.Call) (call *client.Call, err error) {
|
||||||
|
return defsys.Go(ctx, servicePath, serviceMethod, args, reply, done)
|
||||||
|
}
|
||||||
|
|
||||||
|
//服务元数据转服务节点信息
|
||||||
|
func smetaToServiceNode(meta string) (node *ServiceNode, err error) {
|
||||||
|
if meta == "" {
|
||||||
|
fmt.Errorf("meta is nill")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
node = &ServiceNode{}
|
||||||
|
data := make(map[string]string)
|
||||||
|
metadata, _ := url.ParseQuery(meta)
|
||||||
|
for k, v := range metadata {
|
||||||
|
if len(v) > 0 {
|
||||||
|
data[k] = v[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if sid, ok := data["sid"]; !ok {
|
||||||
|
err = fmt.Errorf("no found sid")
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
node.ServiceId = sid
|
||||||
|
}
|
||||||
|
if stype, ok := data["stype"]; !ok {
|
||||||
|
err = fmt.Errorf("no found stype")
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
node.ServiceType = stype
|
||||||
|
}
|
||||||
|
if version, ok := data["version"]; !ok {
|
||||||
|
err = fmt.Errorf("no found version")
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
node.Version = version
|
||||||
|
}
|
||||||
|
if addr, ok := data["addr"]; !ok {
|
||||||
|
err = fmt.Errorf("no found addr")
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
node.ServiceAddr = addr
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
@ -1,31 +1,68 @@
|
|||||||
package rpcx
|
package rpcx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
"go_dreamfactory/lego/utils/mapstructure"
|
"go_dreamfactory/lego/utils/mapstructure"
|
||||||
|
)
|
||||||
|
|
||||||
"github.com/smallnest/rpcx/client"
|
type RpcxStartType int8
|
||||||
|
|
||||||
|
const (
|
||||||
|
RpcxStartByService RpcxStartType = iota //启动服务端
|
||||||
|
RpcxStartByClient //启动客户端
|
||||||
|
RpcxStartByAll //服务端客户端都启动
|
||||||
)
|
)
|
||||||
|
|
||||||
type Option func(*Options)
|
type Option func(*Options)
|
||||||
type Options struct {
|
type Options struct {
|
||||||
|
ServiceTag string //集群标签
|
||||||
|
ServiceType string //服务类型
|
||||||
ServiceId string //服务id
|
ServiceId string //服务id
|
||||||
Port int //监听地址
|
ServiceVersion string //服务版本
|
||||||
FailMode client.FailMode //失败模式
|
ServiceAddr string //服务地址
|
||||||
|
ConsulServers []string //Consul集群服务地址
|
||||||
|
RpcxStartType RpcxStartType //Rpcx启动类型
|
||||||
Debug bool //日志是否开启
|
Debug bool //日志是否开启
|
||||||
Log log.ILog
|
Log log.ILog
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetServiceTag(v string) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.ServiceTag = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetServiceType(v string) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.ServiceType = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func SetServiceId(v string) Option {
|
func SetServiceId(v string) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.ServiceId = v
|
o.ServiceId = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func SetPort(v int) Option {
|
|
||||||
|
func SetServiceVersion(v string) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.Port = v
|
o.ServiceVersion = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetServiceAddr(v string) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.ServiceAddr = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetConsulServers(v []string) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.ConsulServers = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func SetDebug(v bool) Option {
|
func SetDebug(v bool) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.Debug = v
|
o.Debug = v
|
||||||
@ -37,7 +74,7 @@ func SetLog(v log.ILog) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newOptions(config map[string]interface{}, opts ...Option) Options {
|
func newOptions(config map[string]interface{}, opts ...Option) (Options, error) {
|
||||||
options := Options{
|
options := Options{
|
||||||
Debug: true,
|
Debug: true,
|
||||||
Log: log.Clone(log.SetLoglayer(2)),
|
Log: log.Clone(log.SetLoglayer(2)),
|
||||||
@ -48,10 +85,13 @@ func newOptions(config map[string]interface{}, opts ...Option) Options {
|
|||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
o(&options)
|
o(&options)
|
||||||
}
|
}
|
||||||
return options
|
if len(options.ServiceTag) == 0 || len(options.ServiceType) == 0 || len(options.ServiceId) == 0 || len(options.ConsulServers) == 0 {
|
||||||
|
return options, errors.New("[Sys.RPCX] newOptions err: 启动参数异常")
|
||||||
|
}
|
||||||
|
return options, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newOptionsByOption(opts ...Option) Options {
|
func newOptionsByOption(opts ...Option) (Options, error) {
|
||||||
options := Options{
|
options := Options{
|
||||||
Debug: true,
|
Debug: true,
|
||||||
Log: log.Clone(log.SetLoglayer(2)),
|
Log: log.Clone(log.SetLoglayer(2)),
|
||||||
@ -59,5 +99,8 @@ func newOptionsByOption(opts ...Option) Options {
|
|||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
o(&options)
|
o(&options)
|
||||||
}
|
}
|
||||||
return options
|
if len(options.ServiceTag) == 0 || len(options.ServiceType) == 0 || len(options.ServiceId) == 0 || len(options.ConsulServers) == 0 {
|
||||||
|
return options, errors.New("[Sys.RPCX] newOptions err: 启动参数异常")
|
||||||
|
}
|
||||||
|
return options, nil
|
||||||
}
|
}
|
||||||
|
@ -1,40 +1,60 @@
|
|||||||
package rpcx
|
package rpcx
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/smallnest/rpcx/client"
|
||||||
|
)
|
||||||
|
|
||||||
func newSys(options Options) (sys *RPCX, err error) {
|
func newSys(options Options) (sys *RPCX, err error) {
|
||||||
sys = &RPCX{
|
sys = &RPCX{
|
||||||
options: options,
|
options: options,
|
||||||
service: newService(options),
|
metadata: fmt.Sprintf("stype=%s&sid=%s&version=%s&addr=%s", options.ServiceType, options.ServiceId, options.ServiceVersion, "tcp@"+options.ServiceAddr),
|
||||||
}
|
}
|
||||||
|
sys.service, err = newService(sys)
|
||||||
|
sys.client = newClient(sys)
|
||||||
|
// if options.RpcxStartType == RpcxStartByAll || options.RpcxStartType == RpcxStartByService { //创建RPCX 服务端
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if options.RpcxStartType == RpcxStartByAll || options.RpcxStartType == RpcxStartByClient { //创建RPCX 客户端
|
||||||
|
|
||||||
|
// }
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type RPCX struct {
|
type RPCX struct {
|
||||||
options Options
|
options Options
|
||||||
|
metadata string
|
||||||
service IRPCXServer
|
service IRPCXServer
|
||||||
|
client IRPCXClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RPCX) Start() (err error) {
|
func (this *RPCX) Start() (err error) {
|
||||||
this.service.Start()
|
this.service.Start()
|
||||||
|
this.client.Start()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RPCX) Stop() (err error) {
|
func (this *RPCX) Stop() (err error) {
|
||||||
err = this.service.Stop()
|
this.service.Stop()
|
||||||
|
this.client.Stop()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RPCX) Register(rcvr interface{}) (err error) {
|
func (this *RPCX) Register(rcvr interface{}) (err error) {
|
||||||
err = this.service.Register(rcvr)
|
this.service.Register(rcvr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RPCX) RegisterFunction(fn interface{}) (err error) {
|
func (this *RPCX) RegisterFunction(fn interface{}) (err error) {
|
||||||
err = this.service.RegisterFunction(fn)
|
this.service.RegisterFunction(fn)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RPCX) RegisterFunctionName(name string, fn interface{}) (err error) {
|
func (this *RPCX) RegisterFunctionName(name string, fn interface{}) (err error) {
|
||||||
err = this.service.RegisterFunctionName(name, fn)
|
this.service.RegisterFunctionName(name, fn)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,6 +62,54 @@ func (this *RPCX) UnregisterAll() (err error) {
|
|||||||
return this.service.UnregisterAll()
|
return this.service.UnregisterAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *RPCX) NewRpcClient(addr, sId string) (clent IRPCXClient, err error) {
|
//同步调用
|
||||||
return newClient(addr, sId)
|
func (this *RPCX) Call(ctx context.Context, servicePath string, serviceMethod string, args interface{}, reply interface{}) (err error) {
|
||||||
|
return this.client.Call(ctx, servicePath, serviceMethod, args, reply)
|
||||||
|
}
|
||||||
|
|
||||||
|
//异步调用
|
||||||
|
func (this *RPCX) Go(ctx context.Context, servicePath string, serviceMethod string, args interface{}, reply interface{}, done chan *client.Call) (call *client.Call, err error) {
|
||||||
|
return this.client.Go(ctx, servicePath, serviceMethod, args, reply, done)
|
||||||
|
}
|
||||||
|
|
||||||
|
// func (this *RPCX) PostCall(ctx context.Context, serviceName, methodName string, args, reply interface{}) (interface{}, error) {
|
||||||
|
// clientConn := ctx.Value(server.RemoteConnContextKey).(net.Conn)
|
||||||
|
// fmt.Printf("PostCall servicePath:%v serviceMethod:%v RemoteAddr:%v \n", serviceName, methodName, clientConn.RemoteAddr().String())
|
||||||
|
// return args, nil
|
||||||
|
// }
|
||||||
|
|
||||||
|
///日志***********************************************************************
|
||||||
|
func (this *RPCX) Debug() bool {
|
||||||
|
return this.options.Debug
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *RPCX) Debugf(format string, a ...interface{}) {
|
||||||
|
if this.options.Debug {
|
||||||
|
this.options.Log.Debugf("[SYS RPCX] "+format, a...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func (this *RPCX) Infof(format string, a ...interface{}) {
|
||||||
|
if this.options.Debug {
|
||||||
|
this.options.Log.Infof("[SYS RPCX] "+format, a...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func (this *RPCX) Warnf(format string, a ...interface{}) {
|
||||||
|
if this.options.Debug {
|
||||||
|
this.options.Log.Warnf("[SYS RPCX] "+format, a...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func (this *RPCX) Errorf(format string, a ...interface{}) {
|
||||||
|
if this.options.Debug {
|
||||||
|
this.options.Log.Errorf("[SYS RPCX] "+format, a...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func (this *RPCX) Panicf(format string, a ...interface{}) {
|
||||||
|
if this.options.Debug {
|
||||||
|
this.options.Log.Panicf("[SYS RPCX] "+format, a...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func (this *RPCX) Fatalf(format string, a ...interface{}) {
|
||||||
|
if this.options.Debug {
|
||||||
|
this.options.Log.Fatalf("[SYS RPCX] "+format, a...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
178
lego/sys/rpcx/rpcx_test.go
Normal file
178
lego/sys/rpcx/rpcx_test.go
Normal file
@ -0,0 +1,178 @@
|
|||||||
|
package rpcx
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"go_dreamfactory/lego/sys/log"
|
||||||
|
|
||||||
|
"github.com/rcrowley/go-metrics"
|
||||||
|
"github.com/smallnest/rpcx/client"
|
||||||
|
"github.com/smallnest/rpcx/protocol"
|
||||||
|
"github.com/smallnest/rpcx/server"
|
||||||
|
"github.com/smallnest/rpcx/serverplugin"
|
||||||
|
"github.com/smallnest/rpcx/share"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_Sys(t *testing.T) {
|
||||||
|
if err := log.OnInit(nil); err != nil {
|
||||||
|
fmt.Printf("err:%v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if sys, err := NewSys(
|
||||||
|
SetServiceTag("dreamfactory"),
|
||||||
|
SetServiceType("worker"),
|
||||||
|
SetServiceId("worker_1"),
|
||||||
|
SetServiceVersion("1.0.0"),
|
||||||
|
SetServiceAddr("127.0.0.1:9978"),
|
||||||
|
SetConsulServers([]string{"10.0.0.9:8500"}),
|
||||||
|
); err != nil {
|
||||||
|
fmt.Printf("err:%v", err)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
if err = sys.Register(new(Arith)); err != nil {
|
||||||
|
fmt.Printf("err:%v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = sys.Start(); err != nil {
|
||||||
|
fmt.Printf("err:%v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
time.Sleep(time.Second * 3)
|
||||||
|
if err = sys.Call(context.Background(), "worker/worker_1", "Mul", &Args{A: 1, B: 2}, &Reply{}); err != nil {
|
||||||
|
fmt.Printf("Call:%v \n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
sigterm := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(sigterm, syscall.SIGINT, syscall.SIGTERM)
|
||||||
|
select {
|
||||||
|
case <-sigterm:
|
||||||
|
fmt.Printf("terminating: via signal\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var addr = "127.0.0.1:9978"
|
||||||
|
|
||||||
|
// go server.go
|
||||||
|
func Test_RPCX(t *testing.T) {
|
||||||
|
s := server.NewServer()
|
||||||
|
if err := addRegistryPlugin(s); err != nil {
|
||||||
|
fmt.Printf("err:%v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
s.RegisterName("worker", new(Arith), "stype=worker&sid=worker_1&version=1.0.0&addr=tcp@127.0.0.1:9978")
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
time.Sleep(time.Second * 3)
|
||||||
|
if d, err := client.NewConsulDiscovery("rpcx_test", "worker", []string{"10.0.0.9:8500"}, nil); err != nil {
|
||||||
|
fmt.Printf("NewConsulDiscovery err:%v", err)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
xclient := client.NewXClient("worker", client.Failfast, client.RandomSelect, d, client.DefaultOption)
|
||||||
|
xclient.SetSelector(newSelector())
|
||||||
|
ctx := context.WithValue(context.Background(), share.ReqMetaDataKey, map[string]string{"RoutRules": "worker/worker_1"})
|
||||||
|
if err = xclient.Call(ctx, "Mul", &Args{A: 1, B: 2}, &Reply{}); err != nil {
|
||||||
|
fmt.Printf("Call:%v \n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}()
|
||||||
|
|
||||||
|
s.Serve("tcp", addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func addRegistryPlugin(s *server.Server) (err error) {
|
||||||
|
r := &serverplugin.ConsulRegisterPlugin{
|
||||||
|
ServiceAddress: "tcp@" + addr,
|
||||||
|
ConsulServers: []string{"10.0.0.9:8500"},
|
||||||
|
BasePath: "rpcx_test",
|
||||||
|
Metrics: metrics.NewRegistry(),
|
||||||
|
UpdateInterval: time.Minute,
|
||||||
|
}
|
||||||
|
err = r.Start()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Plugins.Add(r)
|
||||||
|
s.Plugins.Add(&call{})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
type call struct{}
|
||||||
|
|
||||||
|
// func (this *call) PostCall(ctx context.Context, serviceName, methodName string, args, reply interface{}) (interface{}, error) {
|
||||||
|
// clientConn := ctx.Value(server.RemoteConnContextKey).(net.Conn)
|
||||||
|
// RoutRules := ctx.Value("RoutRules")
|
||||||
|
// fmt.Printf("PostCall servicePath:%v serviceMethod:%v RoutRules:%s RemoteAddr:%v \n", serviceName, methodName, RoutRules, clientConn.RemoteAddr().String())
|
||||||
|
// return args, nil
|
||||||
|
// }
|
||||||
|
|
||||||
|
// func (this *call) PreCall(ctx context.Context, serviceName, methodName string, args interface{}) (interface{}, error) {
|
||||||
|
// clientConn := ctx.Value(server.RemoteConnContextKey).(net.Conn)
|
||||||
|
// RoutRules := ctx.Value("RoutRules").(string)
|
||||||
|
// fmt.Printf("PostCall servicePath:%v serviceMethod:%v RoutRules:%s RemoteAddr:%v \n", serviceName, methodName, RoutRules, clientConn.RemoteAddr().String())
|
||||||
|
// return args, nil
|
||||||
|
// }
|
||||||
|
|
||||||
|
// func (this *call) PreReadRequest(ctx context.Context) error {
|
||||||
|
// clientConn := ctx.Value(server.RemoteConnContextKey).(net.Conn)
|
||||||
|
// RoutRules := ctx.Value(share.ReqMetaDataKey).(map[string]string)
|
||||||
|
// fmt.Printf("PreReadRequest RoutRules:%s RemoteAddr:%v \n", RoutRules, clientConn.RemoteAddr().String())
|
||||||
|
// return nil
|
||||||
|
// }
|
||||||
|
|
||||||
|
// func (this *call) PreWriteResponse(ctx context.Context, args *protocol.Message, repy *protocol.Message, errInter error) error {
|
||||||
|
// clientConn := ctx.Value(server.RemoteConnContextKey).(net.Conn)
|
||||||
|
// RoutRules := ctx.Value("RoutRules").(string)
|
||||||
|
// fmt.Printf("PreReadRequest RoutRules:%s RemoteAddr:%v \n", RoutRules, clientConn.RemoteAddr().String())
|
||||||
|
// return nil
|
||||||
|
// }
|
||||||
|
|
||||||
|
func (this *call) PreHandleRequest(ctx context.Context, r *protocol.Message) error {
|
||||||
|
clientConn := ctx.Value(server.RemoteConnContextKey).(net.Conn)
|
||||||
|
RoutRules := ctx.Value(share.ReqMetaDataKey).(map[string]string)
|
||||||
|
fmt.Printf("PreReadRequest RoutRules:%s RemoteAddr:%v \n", RoutRules, clientConn.RemoteAddr().String())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type Args struct {
|
||||||
|
A int
|
||||||
|
B int
|
||||||
|
}
|
||||||
|
|
||||||
|
type Reply struct {
|
||||||
|
C int
|
||||||
|
}
|
||||||
|
|
||||||
|
type Arith int
|
||||||
|
|
||||||
|
func (t *Arith) Mul(ctx context.Context, args *Args, reply *Reply) error {
|
||||||
|
reply.C = args.A * args.B
|
||||||
|
fmt.Printf("call: %d * %d = %d\n", args.A, args.B, reply.C)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Arith) Add(ctx context.Context, args *Args, reply *Reply) error {
|
||||||
|
reply.C = args.A + args.B
|
||||||
|
fmt.Printf("call: %d + %d = %d\n", args.A, args.B, reply.C)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Arith) Say(ctx context.Context, args *string, reply *string) error {
|
||||||
|
*reply = "hello " + *args
|
||||||
|
return nil
|
||||||
|
}
|
77
lego/sys/rpcx/selector.go
Normal file
77
lego/sys/rpcx/selector.go
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
package rpcx
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"go_dreamfactory/lego/sys/log"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/smallnest/rpcx/share"
|
||||||
|
)
|
||||||
|
|
||||||
|
func newSelector() *Selector {
|
||||||
|
return &Selector{
|
||||||
|
servers: make(map[string]*ServiceNode),
|
||||||
|
serversType: make(map[string][]*ServiceNode),
|
||||||
|
i: make(map[string]int),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type ServiceNode struct {
|
||||||
|
ServiceId string `json:"sid"` //服务id
|
||||||
|
ServiceType string `json:"stype"` //服务类型
|
||||||
|
Version string `json:"version"` //服务版本
|
||||||
|
ServiceAddr string `json:"addr"` //服务地址
|
||||||
|
}
|
||||||
|
|
||||||
|
type Selector struct {
|
||||||
|
servers map[string]*ServiceNode
|
||||||
|
serversType map[string][]*ServiceNode
|
||||||
|
i map[string]int
|
||||||
|
}
|
||||||
|
|
||||||
|
///servicePath = [stype] or [stype/sid]
|
||||||
|
func (this *Selector) Select(ctx context.Context, servicePath, serviceMethod string, args interface{}) string {
|
||||||
|
fmt.Printf("Select servicePath:%v serviceMethod:%v ReqMetaData:%v \n", servicePath, serviceMethod, ctx.Value(share.ReqMetaDataKey))
|
||||||
|
routrules := ctx.Value(share.ReqMetaDataKey).(map[string]string)[CallRoutRulesKey]
|
||||||
|
service := strings.Split(routrules, "/")
|
||||||
|
leng := len(service)
|
||||||
|
if leng == 1 {
|
||||||
|
if nodes, ok := this.serversType[service[0]]; ok {
|
||||||
|
i, ok := this.i[service[0]]
|
||||||
|
if !ok {
|
||||||
|
i = 0
|
||||||
|
}
|
||||||
|
i = i % len(nodes)
|
||||||
|
this.i[service[0]] = i + 1
|
||||||
|
return nodes[i].ServiceAddr
|
||||||
|
}
|
||||||
|
} else if leng == 2 {
|
||||||
|
if node, ok := this.servers[service[1]]; ok {
|
||||||
|
return node.ServiceAddr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Selector) UpdateServer(servers map[string]string) {
|
||||||
|
ss := make(map[string]*ServiceNode)
|
||||||
|
sst := make(map[string][]*ServiceNode)
|
||||||
|
for _, v := range servers {
|
||||||
|
if node, err := smetaToServiceNode(v); err != nil {
|
||||||
|
log.Errorf("smetaToServiceNode:%s err:%v", v, err)
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
ss[node.ServiceId] = node
|
||||||
|
if ssts, ok := sst[node.ServiceType]; !ok {
|
||||||
|
sst[node.ServiceType] = make([]*ServiceNode, 0)
|
||||||
|
sst[node.ServiceType] = append(sst[node.ServiceType], node)
|
||||||
|
} else {
|
||||||
|
ssts = append(ssts, node)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
this.servers = ss
|
||||||
|
this.serversType = sst
|
||||||
|
}
|
@ -1,26 +1,54 @@
|
|||||||
package rpcx
|
package rpcx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"context"
|
||||||
|
"go_dreamfactory/lego/sys/log"
|
||||||
|
"net"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/rcrowley/go-metrics"
|
||||||
|
"github.com/smallnest/rpcx/client"
|
||||||
"github.com/smallnest/rpcx/server"
|
"github.com/smallnest/rpcx/server"
|
||||||
|
"github.com/smallnest/rpcx/serverplugin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newService(options Options) (s *Service) {
|
func newService(rpcx *RPCX) (s *Service, err error) {
|
||||||
s = &Service{
|
s = &Service{
|
||||||
server: server.NewServer(),
|
server: server.NewServer(),
|
||||||
options: options,
|
rpcx: rpcx,
|
||||||
|
// clients: make(map[string]net.Conn),
|
||||||
|
// clientmeta: make(map[string]string),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r := &serverplugin.ConsulRegisterPlugin{
|
||||||
|
ServiceAddress: "tcp@" + rpcx.options.ServiceAddr,
|
||||||
|
ConsulServers: []string{"10.0.0.9:8500"},
|
||||||
|
BasePath: rpcx.options.ServiceTag,
|
||||||
|
Metrics: metrics.NewRegistry(),
|
||||||
|
UpdateInterval: time.Minute,
|
||||||
|
}
|
||||||
|
if err = r.Start(); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.server.Plugins.Add(r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
|
rpcx *RPCX
|
||||||
server *server.Server
|
server *server.Server
|
||||||
options Options
|
selector client.Selector
|
||||||
|
clients map[string]net.Conn
|
||||||
|
clientmeta map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Service) Start() (err error) {
|
func (this *Service) Start() (err error) {
|
||||||
go this.server.Serve("tcp", fmt.Sprintf(":%d", this.options.Port))
|
|
||||||
|
go func() {
|
||||||
|
if err = this.server.Serve("tcp", this.rpcx.options.ServiceAddr); err != nil {
|
||||||
|
log.Errorf("rpcx server exit!")
|
||||||
|
}
|
||||||
|
}()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,18 +58,80 @@ func (this *Service) Stop() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *Service) Register(rcvr interface{}) (err error) {
|
func (this *Service) Register(rcvr interface{}) (err error) {
|
||||||
err = this.server.RegisterName(this.options.ServiceId, rcvr, "")
|
err = this.server.RegisterName(this.rpcx.options.ServiceType, rcvr, this.rpcx.metadata)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Service) RegisterFunction(fn interface{}) (err error) {
|
func (this *Service) RegisterFunction(fn interface{}) (err error) {
|
||||||
err = this.server.RegisterFunction(this.options.ServiceId, fn, "")
|
err = this.server.RegisterFunction(this.rpcx.options.ServiceType, fn, this.rpcx.metadata)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func (this *Service) RegisterFunctionName(name string, fn interface{}) (err error) {
|
func (this *Service) RegisterFunctionName(name string, fn interface{}) (err error) {
|
||||||
err = this.server.RegisterFunctionName(this.options.ServiceId, name, fn, "")
|
err = this.server.RegisterFunctionName(this.rpcx.options.ServiceType, name, fn, this.rpcx.metadata)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func (this *Service) UnregisterAll() (err error) {
|
func (this *Service) UnregisterAll() (err error) {
|
||||||
err = this.server.UnregisterAll()
|
err = this.server.UnregisterAll()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//同步调用
|
||||||
|
func (this *Service) Call(servicePath string, ctx context.Context, serviceMethod string, args interface{}, reply interface{}) (err error) {
|
||||||
|
// var (
|
||||||
|
// spath string
|
||||||
|
// clientaddr string
|
||||||
|
// conn net.Conn
|
||||||
|
// ok bool
|
||||||
|
// )
|
||||||
|
// if servicePath == "" {
|
||||||
|
// err = errors.New("servicePath no cant null")
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// spath := strings.Split(servicePath, "/")
|
||||||
|
// ctx = context.WithValue(ctx, share.ReqMetaDataKey, map[string]string{
|
||||||
|
// CallRoutRulesKey: servicePath,
|
||||||
|
// ServiceAddrKey: "tcp@" + this.options.ServiceAddr,
|
||||||
|
// ServiceMetaKey: this.metadata,
|
||||||
|
// })
|
||||||
|
// if clientaddr = this.selector.Select(ctx, spath[0], serviceMethod, args); clientaddr == "" {
|
||||||
|
// err = fmt.Errorf("on found routRules:%s", routRules)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// if conn, ok = this.clients[clientaddr]; !ok {
|
||||||
|
// err = fmt.Errorf("on found clientaddr:%s", clientaddr)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// err := this.server.SendMessage(conn, spath[0], serviceMethod, nil, []byte("abcde")){
|
||||||
|
|
||||||
|
// }
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//异步调用
|
||||||
|
func (this *Service) Go(routRules string, ctx context.Context, serviceMethod string, args interface{}, reply interface{}) (err error) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//发现服务
|
||||||
|
func (this *Service) Discovery(addr string, conn net.Conn, meta string) {
|
||||||
|
this.clientmeta[addr] = meta
|
||||||
|
this.clients[addr] = conn
|
||||||
|
this.selector.UpdateServer(this.clientmeta)
|
||||||
|
}
|
||||||
|
|
||||||
|
// //监听客户端链接到服务上 保存客户端的连接对象
|
||||||
|
// func (this *Service) PreHandleRequest(ctx context.Context, r *protocol.Message) error {
|
||||||
|
// if smeta, ok := ctx.Value(share.ReqMetaDataKey).(map[string]string)[ServiceAddrKey]; ok {
|
||||||
|
// // log.Errorf("smeta:%s err:%v", smeta, ok)
|
||||||
|
// if node, err := smetaToServiceNode(smeta); err == nil {
|
||||||
|
// if _, ok = this.clientmeta[node.ServiceId]; !ok {
|
||||||
|
// this.clientmeta[node.ServiceId] = smeta
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // clientConn := ctx.Value(server.RemoteConnContextKey).(net.Conn)
|
||||||
|
|
||||||
|
// // fmt.Printf("PreReadRequest RoutRules:%s RemoteAddr:%v \n", RoutRules, clientConn.RemoteAddr().String())
|
||||||
|
// return nil
|
||||||
|
// }
|
||||||
|
@ -8,12 +8,20 @@ import (
|
|||||||
"go_dreamfactory/modules"
|
"go_dreamfactory/modules"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
"go_dreamfactory/sys/cache"
|
"go_dreamfactory/sys/cache"
|
||||||
|
"go_dreamfactory/sys/db"
|
||||||
"go_dreamfactory/utils"
|
"go_dreamfactory/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
Friend_SubType_List = "list"
|
||||||
Friend_SubType_Apply = "apply"
|
Friend_SubType_Apply = "apply"
|
||||||
Friend_SubType_ApplyList = "applylist"
|
Friend_SubType_ApplyList = "applylist"
|
||||||
|
Friend_SubType_AddBlack = "addblack"
|
||||||
|
Friend_SubType_DelBlack = "delblack"
|
||||||
|
Friend_SubType_Blacklist = "blacklist"
|
||||||
|
Friend_SubType_Agree = "agree"
|
||||||
|
Friend_SubType_Refuse = "refuse"
|
||||||
|
Friend_SubType_Search = "search"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FriendComp struct {
|
type FriendComp struct {
|
||||||
@ -29,6 +37,27 @@ func (this *FriendComp) Init(service core.IService, module core.IModule, comp co
|
|||||||
|
|
||||||
//搜索
|
//搜索
|
||||||
func (this *FriendComp) Search(ctx context.Context, session comm.IUserSession, req *pb.FriendSearchReq) error {
|
func (this *FriendComp) Search(ctx context.Context, session comm.IUserSession, req *pb.FriendSearchReq) error {
|
||||||
|
var (
|
||||||
|
code pb.ErrorCode
|
||||||
|
rsp *pb.FriendSearchRsp
|
||||||
|
friend *pb.FriendBase
|
||||||
|
)
|
||||||
|
defer func() {
|
||||||
|
if code == pb.ErrorCode_Success {
|
||||||
|
rsp = &pb.FriendSearchRsp{
|
||||||
|
Friend: friend,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
session.SendMsg(string(this.module.GetType()), Friend_SubType_Search, code, rsp)
|
||||||
|
}()
|
||||||
|
|
||||||
|
user := db.Defsys.Frined_FindCond(req.NickName)
|
||||||
|
if user != nil {
|
||||||
|
friend = &pb.FriendBase{
|
||||||
|
UserId: user.Uid,
|
||||||
|
NickName: user.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +144,7 @@ func (this *FriendComp) Apply(ctx context.Context, session comm.IUserSession, re
|
|||||||
|
|
||||||
//将自己加入到目标用户的申请列表中
|
//将自己加入到目标用户的申请列表中
|
||||||
target.ApplyIds = append(target.ApplyIds, self.UserId)
|
target.ApplyIds = append(target.ApplyIds, self.UserId)
|
||||||
err = cache.Defsys.Friend_Apply(&pb.Cache_FriendData{
|
err = cache.Defsys.Friend_Update(&pb.Cache_FriendData{
|
||||||
UserId: req.FriendId,
|
UserId: req.FriendId,
|
||||||
ApplyIds: target.ApplyIds,
|
ApplyIds: target.ApplyIds,
|
||||||
})
|
})
|
||||||
@ -138,12 +167,6 @@ func (this *FriendComp) ApplyList(ctx context.Context, session comm.IUserSession
|
|||||||
list []*pb.FriendBase
|
list []*pb.FriendBase
|
||||||
)
|
)
|
||||||
|
|
||||||
self, err = cache.Defsys.Friend_Get(session.GetUserId())
|
|
||||||
if self == nil || err != nil {
|
|
||||||
code = pb.ErrorCode_FriendSelfNoData
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if code == pb.ErrorCode_Success {
|
if code == pb.ErrorCode_Success {
|
||||||
rsp = &pb.FriendApplyListRsp{
|
rsp = &pb.FriendApplyListRsp{
|
||||||
@ -153,6 +176,12 @@ func (this *FriendComp) ApplyList(ctx context.Context, session comm.IUserSession
|
|||||||
session.SendMsg(string(this.module.GetType()), Friend_SubType_ApplyList, code, rsp)
|
session.SendMsg(string(this.module.GetType()), Friend_SubType_ApplyList, code, rsp)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
self, err = cache.Defsys.Friend_Get(session.GetUserId())
|
||||||
|
if self == nil || err != nil {
|
||||||
|
code = pb.ErrorCode_FriendSelfNoData
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
for _, userId := range self.ApplyIds {
|
for _, userId := range self.ApplyIds {
|
||||||
//TODO 组装FriendBase明细数据
|
//TODO 组装FriendBase明细数据
|
||||||
list = append(list, &pb.FriendBase{
|
list = append(list, &pb.FriendBase{
|
||||||
@ -169,28 +198,142 @@ func (this *FriendComp) Del(ctx context.Context, session comm.IUserSession, req
|
|||||||
}
|
}
|
||||||
|
|
||||||
//好友列表
|
//好友列表
|
||||||
func (this *FriendComp) List(ctx context.Context, session comm.IUserSession, req *pb.FriendListReq) error {
|
func (this *FriendComp) List(ctx context.Context, session comm.IUserSession, req *pb.FriendListReq) (err error) {
|
||||||
|
var (
|
||||||
|
code pb.ErrorCode
|
||||||
|
self *pb.Cache_FriendData
|
||||||
|
rsp *pb.FriendListRsp
|
||||||
|
list []*pb.FriendBase
|
||||||
|
)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if code == pb.ErrorCode_Success {
|
||||||
|
rsp = &pb.FriendListRsp{
|
||||||
|
List: list,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
session.SendMsg(string(this.module.GetType()), Friend_SubType_List, code, rsp)
|
||||||
|
}()
|
||||||
|
|
||||||
|
self, err = cache.Defsys.Friend_Get(session.GetUserId())
|
||||||
|
if self == nil || err != nil {
|
||||||
|
code = pb.ErrorCode_FriendSelfNoData
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, userId := range self.FriendIds {
|
||||||
|
list = append(list, &pb.FriendBase{
|
||||||
|
UserId: userId,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//单个/批量同意
|
//单个/批量同意
|
||||||
func (this *FriendComp) Agree(ctx context.Context, session comm.IUserSession, req *pb.FriendAgreeOrRefuseReq) error {
|
func (this *FriendComp) Agree(ctx context.Context, session comm.IUserSession, req *pb.FriendAgreeReq) (err error) {
|
||||||
|
var (
|
||||||
|
code pb.ErrorCode
|
||||||
|
self *pb.Cache_FriendData
|
||||||
|
rsp *pb.FriendAgreeRsp
|
||||||
|
optNum int32
|
||||||
|
)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if code == pb.ErrorCode_Success {
|
||||||
|
rsp = &pb.FriendAgreeRsp{
|
||||||
|
Num: optNum,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
session.SendMsg(string(this.module.GetType()), Friend_SubType_Agree, code, rsp)
|
||||||
|
}()
|
||||||
|
|
||||||
|
self, err = cache.Defsys.Friend_Get(session.GetUserId())
|
||||||
|
if self == nil || err != nil {
|
||||||
|
code = pb.ErrorCode_FriendSelfNoData
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//将申请人加入到自己的好友列表中
|
||||||
|
for _, userId := range req.FriendIds {
|
||||||
|
if _, ok := utils.Find(self.FriendIds, userId); !ok {
|
||||||
|
self.FriendIds = append(self.FriendIds, userId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//将自己加入到申请人的好友列表中
|
||||||
|
for _, userId := range req.FriendIds {
|
||||||
|
target, err2 := cache.Defsys.Friend_Get(userId)
|
||||||
|
if target == nil || err2 != nil {
|
||||||
|
code = pb.ErrorCode_FriendTargetNoData
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//将申请人从申请列表中删除
|
||||||
|
for _, userId := range req.FriendIds {
|
||||||
|
self.ApplyIds = utils.DeleteString(self.ApplyIds, userId)
|
||||||
|
optNum++
|
||||||
|
}
|
||||||
|
|
||||||
|
//更新
|
||||||
|
err = cache.Defsys.Friend_Update(self)
|
||||||
|
if err != nil {
|
||||||
|
code = pb.ErrorCode_DBError
|
||||||
|
return
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//单个/批量拒绝
|
//单个/批量拒绝
|
||||||
func (this *FriendComp) Refuse(ctx context.Context, session comm.IUserSession, req *pb.FriendAgreeOrRefuseReq) error {
|
func (this *FriendComp) Refuse(ctx context.Context, session comm.IUserSession, req *pb.FriendRefuseReq) (err error) {
|
||||||
|
//将申请人从申请列表中删除
|
||||||
|
var (
|
||||||
|
code pb.ErrorCode
|
||||||
|
self *pb.Cache_FriendData
|
||||||
|
rsp *pb.FriendAgreeRsp
|
||||||
|
optNum int32
|
||||||
|
)
|
||||||
|
defer func() {
|
||||||
|
if code == pb.ErrorCode_Success {
|
||||||
|
rsp = &pb.FriendAgreeRsp{
|
||||||
|
Num: optNum,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
session.SendMsg(string(this.module.GetType()), Friend_SubType_Refuse, code, rsp)
|
||||||
|
}()
|
||||||
|
|
||||||
|
self, err = cache.Defsys.Friend_Get(session.GetUserId())
|
||||||
|
if self == nil || err != nil {
|
||||||
|
code = pb.ErrorCode_FriendSelfNoData
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//将申请人从申请列表中删除
|
||||||
|
for _, userId := range req.FriendIds {
|
||||||
|
self.ApplyIds = utils.DeleteString(self.ApplyIds, userId)
|
||||||
|
optNum++
|
||||||
|
}
|
||||||
|
|
||||||
|
//更新
|
||||||
|
err = cache.Defsys.Friend_Update(self)
|
||||||
|
if err != nil {
|
||||||
|
code = pb.ErrorCode_DBError
|
||||||
|
return
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//赠送或接收
|
//赠送或接收
|
||||||
func (this *FriendComp) ReceSend(ctx context.Context, session comm.IUserSession, req *pb.FriendReceiveOrSendReq) error {
|
func (this *FriendComp) ReceSend(ctx context.Context, session comm.IUserSession, req *pb.FriendReceiveReq) error {
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
//好友数量
|
|
||||||
func (this *FriendComp) Total(ctx context.Context, session comm.IUserSession, req *pb.FriendTotalReq) error {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,11 +343,129 @@ func (this *FriendComp) Detail(ctx context.Context, session comm.IUserSession, r
|
|||||||
}
|
}
|
||||||
|
|
||||||
//黑名单
|
//黑名单
|
||||||
func (this *FriendComp) Blacklist(ctx context.Context, session comm.IUserSession, req *pb.FriendBlackListReq) error {
|
func (this *FriendComp) Blacklist(ctx context.Context, session comm.IUserSession, req *pb.FriendBlackListReq) (err error) {
|
||||||
|
var (
|
||||||
|
code pb.ErrorCode
|
||||||
|
self *pb.Cache_FriendData
|
||||||
|
rsp *pb.FriendBlackListRsp
|
||||||
|
list []*pb.FriendBase
|
||||||
|
)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if code == pb.ErrorCode_Success {
|
||||||
|
rsp = &pb.FriendBlackListRsp{
|
||||||
|
Friends: list,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
session.SendMsg(string(this.module.GetType()), Friend_SubType_Blacklist, code, rsp)
|
||||||
|
}()
|
||||||
|
|
||||||
|
self, err = cache.Defsys.Friend_Get(session.GetUserId())
|
||||||
|
if self == nil || err != nil {
|
||||||
|
code = pb.ErrorCode_FriendSelfNoData
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, userId := range self.BlackIds {
|
||||||
|
//TODO 完善FriendBase信息
|
||||||
|
list = append(list, &pb.FriendBase{
|
||||||
|
UserId: userId,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//加入黑名单
|
//加入黑名单
|
||||||
func (this *FriendComp) Addblack(ctx context.Context, session comm.IUserSession, req *pb.FriendBlackAddReq) error {
|
func (this *FriendComp) Addblack(ctx context.Context, session comm.IUserSession, req *pb.FriendBlackAddReq) (err error) {
|
||||||
|
var (
|
||||||
|
code pb.ErrorCode
|
||||||
|
self *pb.Cache_FriendData
|
||||||
|
target *pb.Cache_FriendData
|
||||||
|
rsp *pb.FriendBlackAddRsp
|
||||||
|
blackNumMax = 50 //TODO 从配置中读取
|
||||||
|
)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if code == pb.ErrorCode_Success {
|
||||||
|
rsp = &pb.FriendBlackAddRsp{
|
||||||
|
FriendId: req.FriendId,
|
||||||
|
UserId: session.GetUserId(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
session.SendMsg(string(this.module.GetType()), Friend_SubType_AddBlack, code, rsp)
|
||||||
|
}()
|
||||||
|
|
||||||
|
self, err = cache.Defsys.Friend_Get(session.GetUserId())
|
||||||
|
if self == nil || err != nil {
|
||||||
|
code = pb.ErrorCode_FriendSelfNoData
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
target, err = cache.Defsys.Friend_Get(req.FriendId)
|
||||||
|
if target == nil || err != nil {
|
||||||
|
code = pb.ErrorCode_FriendTargetNoData
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//判断目标是否在好友列表里面
|
||||||
|
if _, ok := utils.Find(self.FriendIds, req.FriendId); ok {
|
||||||
|
code = pb.ErrorCode_FriendSelfBlackYet
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断自己是否在对方的黑名单中
|
||||||
|
if _, ok := utils.Find(target.BlackIds, self.UserId); ok {
|
||||||
|
code = pb.ErrorCode_FriendTargetBlackYet
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断是否黑名单人数已满
|
||||||
|
if len(self.BlackIds) >= blackNumMax {
|
||||||
|
code = pb.ErrorCode_FriendBlackMax
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//将目标加入黑名单
|
||||||
|
self.BlackIds = append(self.BlackIds, req.FriendId)
|
||||||
|
//更新黑名单
|
||||||
|
err = cache.Defsys.Friend_Update(self)
|
||||||
|
if err != nil {
|
||||||
|
code = pb.ErrorCode_DBError
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
//删除黑名单
|
||||||
|
func (this *FriendComp) delblack(ctx context.Context, session comm.IUserSession, req *pb.FriendDelBlackReq) (err error) {
|
||||||
|
var (
|
||||||
|
code pb.ErrorCode
|
||||||
|
self *pb.Cache_FriendData
|
||||||
|
rsp *pb.FriendDelBlackRsp
|
||||||
|
)
|
||||||
|
defer func() {
|
||||||
|
if code == pb.ErrorCode_Success {
|
||||||
|
rsp = &pb.FriendDelBlackRsp{
|
||||||
|
FriendId: req.FriendId,
|
||||||
|
UserId: session.GetUserId(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
session.SendMsg(string(this.module.GetType()), Friend_SubType_AddBlack, code, rsp)
|
||||||
|
}()
|
||||||
|
self, err = cache.Defsys.Friend_Get(session.GetUserId())
|
||||||
|
if self == nil || err != nil {
|
||||||
|
code = pb.ErrorCode_FriendSelfNoData
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//从黑名单列表中删除目标
|
||||||
|
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 nil
|
||||||
}
|
}
|
||||||
|
@ -27,16 +27,17 @@ var typeOfError = reflect.TypeOf((*error)(nil)).Elem()
|
|||||||
*/
|
*/
|
||||||
type MComp_GateComp struct {
|
type MComp_GateComp struct {
|
||||||
cbase.ModuleCompBase
|
cbase.ModuleCompBase
|
||||||
service base.IRPCXService //rpc服务对象
|
S base.IRPCXService //rpc服务对象
|
||||||
module core.IModule //当前业务模块
|
M core.IModule //当前业务模块
|
||||||
comp core.IModuleComp //网关组件自己
|
comp core.IModuleComp //网关组件自己
|
||||||
|
scomp comm.ISC_GateRouteComp
|
||||||
}
|
}
|
||||||
|
|
||||||
//组件初始化接口
|
//组件初始化接口
|
||||||
func (this *MComp_GateComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
func (this *MComp_GateComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||||
this.ModuleCompBase.Init(service, module, comp, options)
|
this.ModuleCompBase.Init(service, module, comp, options)
|
||||||
this.service = service.(base.IRPCXService)
|
this.S = service.(base.IRPCXService)
|
||||||
this.module = module
|
this.M = module
|
||||||
this.comp = comp
|
this.comp = comp
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -48,57 +49,55 @@ func (this *MComp_GateComp) Start() (err error) {
|
|||||||
}
|
}
|
||||||
var comp core.IServiceComp
|
var comp core.IServiceComp
|
||||||
//注册远程路由
|
//注册远程路由
|
||||||
if comp, err = this.service.GetComp(comm.SC_ServiceGateRouteComp); err != nil {
|
if comp, err = this.S.GetComp(comm.SC_ServiceGateRouteComp); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.suitableMethods(comp.(comm.ISC_GateRouteComp), reflect.TypeOf(this.comp))
|
this.scomp = comp.(comm.ISC_GateRouteComp)
|
||||||
|
this.suitableMethods(reflect.TypeOf(this.comp))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//反射注册相关接口道services/comp_gateroute.go 对象中
|
//反射注册相关接口道services/comp_gateroute.go 对象中
|
||||||
func (this *MComp_GateComp) suitableMethods(scomp comm.ISC_GateRouteComp, typ reflect.Type) {
|
func (this *MComp_GateComp) suitableMethods(typ reflect.Type) {
|
||||||
for m := 0; m < typ.NumMethod(); m++ {
|
for m := 0; m < typ.NumMethod(); m++ {
|
||||||
method := typ.Method(m)
|
method := typ.Method(m)
|
||||||
mtype := method.Type
|
this.reflectionRouteHandle(method)
|
||||||
mname := method.Name
|
|
||||||
// Method must be exported.
|
|
||||||
if method.PkgPath != "" {
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
// Method needs four ins: receiver, context.Context, *args, *reply.
|
|
||||||
if mtype.NumIn() != 4 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// First arg must be context.Context
|
|
||||||
ctxType := mtype.In(1)
|
|
||||||
if !ctxType.Implements(typeOfContext) {
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Second arg need not be a pointer.
|
//反射路由处理函数
|
||||||
|
func (this *MComp_GateComp) reflectionRouteHandle(method reflect.Method) bool {
|
||||||
|
mtype := method.Type
|
||||||
|
mname := method.Name
|
||||||
|
if method.PkgPath != "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if mtype.NumIn() != 4 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
ctxType := mtype.In(1)
|
||||||
|
if !ctxType.Implements(typeOfContext) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
argType := mtype.In(2)
|
argType := mtype.In(2)
|
||||||
if !argType.Implements(typeOfSession) {
|
if !argType.Implements(typeOfSession) {
|
||||||
continue
|
return false
|
||||||
}
|
}
|
||||||
// Third arg must be a pointer.
|
|
||||||
replyType := mtype.In(3)
|
replyType := mtype.In(3)
|
||||||
if replyType.Kind() != reflect.Ptr {
|
if replyType.Kind() != reflect.Ptr {
|
||||||
continue
|
return false
|
||||||
}
|
}
|
||||||
// Reply type must be exported.
|
|
||||||
if !this.isExportedOrBuiltinType(replyType) {
|
if !this.isExportedOrBuiltinType(replyType) {
|
||||||
continue
|
return false
|
||||||
}
|
}
|
||||||
// Method needs one out.
|
|
||||||
if mtype.NumOut() != 1 {
|
if mtype.NumOut() != 1 {
|
||||||
continue
|
return false
|
||||||
}
|
}
|
||||||
// The return type of the method must be error.
|
|
||||||
if returnType := mtype.Out(0); returnType != typeOfError {
|
if returnType := mtype.Out(0); returnType != typeOfError {
|
||||||
continue
|
return false
|
||||||
}
|
|
||||||
scomp.RegisterRoute(fmt.Sprintf("%s.%s", this.module.GetType(), strings.ToLower(mname)), reflect.ValueOf(this.comp), replyType, method)
|
|
||||||
}
|
}
|
||||||
|
this.scomp.RegisterRoute(fmt.Sprintf("%s.%s", this.M.GetType(), strings.ToLower(mname)), reflect.ValueOf(this.comp), replyType, method)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *MComp_GateComp) isExportedOrBuiltinType(t reflect.Type) bool {
|
func (this *MComp_GateComp) isExportedOrBuiltinType(t reflect.Type) bool {
|
||||||
|
@ -62,6 +62,7 @@ locp:
|
|||||||
go this.Close()
|
go this.Close()
|
||||||
break locp
|
break locp
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = proto.Unmarshal(data, msg); err != nil {
|
if err = proto.Unmarshal(data, msg); err != nil {
|
||||||
log.Errorf("agent:%s uId:%s Unmarshal err:%v", this.sessionId, this.uId, err)
|
log.Errorf("agent:%s uId:%s Unmarshal err:%v", this.sessionId, this.uId, err)
|
||||||
go this.Close()
|
go this.Close()
|
||||||
@ -142,7 +143,7 @@ func (this *Agent) Close() {
|
|||||||
func (this *Agent) messageDistribution(msg *pb.UserMessage) {
|
func (this *Agent) messageDistribution(msg *pb.UserMessage) {
|
||||||
reply := &pb.RPCMessageReply{}
|
reply := &pb.RPCMessageReply{}
|
||||||
log.Debugf("agent:%s uId:%s MessageDistribution msg:%s.%s", this.sessionId, this.uId, msg.MainType, msg.SubType)
|
log.Debugf("agent:%s uId:%s MessageDistribution msg:%s.%s", this.sessionId, this.uId, msg.MainType, msg.SubType)
|
||||||
if err := this.gateway.Service().RpcCallByType("worker", string(comm.Rpc_GatewayRoute), context.Background(), &pb.AgentMessage{
|
if err := this.gateway.Service().RpcCall(context.Background(), comm.Service_Worker, string(comm.Rpc_GatewayRoute), &pb.AgentMessage{
|
||||||
Ip: this.IP(),
|
Ip: this.IP(),
|
||||||
UserSessionId: this.sessionId,
|
UserSessionId: this.sessionId,
|
||||||
UserId: this.uId,
|
UserId: this.uId,
|
||||||
|
@ -2,6 +2,7 @@ package modules
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
|
|
||||||
@ -10,7 +11,8 @@ import (
|
|||||||
"go_dreamfactory/lego/core/cbase"
|
"go_dreamfactory/lego/core/cbase"
|
||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
|
|
||||||
"google.golang.org/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
|
"github.com/golang/protobuf/ptypes"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -31,14 +33,14 @@ func (this *ModuleBase) Init(service core.IService, module core.IModule, options
|
|||||||
//向指定用户发送消息
|
//向指定用户发送消息
|
||||||
func (this *ModuleBase) SendMsgToUser(mainType, subType string, msg proto.Message, user *pb.Cache_UserData) (err error) {
|
func (this *ModuleBase) SendMsgToUser(mainType, subType string, msg proto.Message, user *pb.Cache_UserData) (err error) {
|
||||||
reply := &pb.RPCMessageReply{}
|
reply := &pb.RPCMessageReply{}
|
||||||
data, _ := proto.Marshal(msg)
|
data, _ := ptypes.MarshalAny(msg)
|
||||||
if _, err = this.service.RpcGoById(user.GatewayServiceId, string(comm.Rpc_GatewayAgentSendMsg), context.Background(), &pb.AgentSendMessageReq{
|
if _, err = this.service.RpcGo(context.Background(), fmt.Sprintf("%s/%s", comm.Service_Gateway, user.GatewayServiceId), string(comm.Rpc_GatewayAgentSendMsg), &pb.AgentSendMessageReq{
|
||||||
UserSessionId: user.SessionId,
|
UserSessionId: user.SessionId,
|
||||||
MainType: mainType,
|
MainType: mainType,
|
||||||
SubType: subType,
|
SubType: subType,
|
||||||
Data: data,
|
Data: data,
|
||||||
}, reply); err != nil {
|
}, reply); err != nil {
|
||||||
log.Errorf("SendMsgToUser%d:%s [%s.%s] err:%v", user.UserData.UserId, user.SessionId, mainType, subType, err)
|
log.Errorf("SendMsgToUser%d:%s [%s.%s] err:%v", user.UserData.Uid, user.SessionId, mainType, subType, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -58,9 +60,9 @@ func (this *ModuleBase) SendMsgToUsers(mainType, subType string, msg proto.Messa
|
|||||||
gateway = append(gateway, v.SessionId)
|
gateway = append(gateway, v.SessionId)
|
||||||
}
|
}
|
||||||
reply := &pb.RPCMessageReply{}
|
reply := &pb.RPCMessageReply{}
|
||||||
data, _ := proto.Marshal(msg)
|
data, _ := ptypes.MarshalAny(msg)
|
||||||
for k, v := range gateways {
|
for k, v := range gateways {
|
||||||
if _, err = this.service.RpcGoById(k, string(comm.Rpc_GatewayAgentSendMsg), context.Background(), &pb.BatchMessageReq{
|
if _, err = this.service.RpcGo(context.Background(), fmt.Sprintf("%s/%s", comm.Service_Gateway, k), string(comm.Rpc_GatewayAgentSendMsg), &pb.BatchMessageReq{
|
||||||
UserSessionIds: v,
|
UserSessionIds: v,
|
||||||
MainType: mainType,
|
MainType: mainType,
|
||||||
SubType: subType,
|
SubType: subType,
|
||||||
|
@ -6,20 +6,37 @@ import (
|
|||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
"go_dreamfactory/sys/cache"
|
"go_dreamfactory/sys/cache"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//参数校验
|
||||||
|
func (this *Api_Comp) Getlist_Check(ctx context.Context, session comm.IUserSession, req *pb.GetlistReq) (code pb.ErrorCode) {
|
||||||
|
if !session.IsLogin() {
|
||||||
|
code = pb.ErrorCode_NoLogin
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
///获取用户道具
|
///获取用户道具
|
||||||
func (this *Api_Comp) Getlist(ctx context.Context, session comm.IUserSession, req *pb.GetlistReq) (err error) {
|
func (this *Api_Comp) Getlist(ctx context.Context, session comm.IUserSession, req *pb.GetlistReq) (err error) {
|
||||||
var (
|
var (
|
||||||
code pb.ErrorCode
|
code pb.ErrorCode
|
||||||
pack *pb.DB_UserPackData
|
pack *pb.DB_UserPackData
|
||||||
|
nt int64
|
||||||
|
tempgrids []*pb.DB_GridData
|
||||||
grids []*pb.DB_GridData
|
grids []*pb.DB_GridData
|
||||||
|
modifys []*pb.DB_GridData
|
||||||
)
|
)
|
||||||
defer func() {
|
defer func() {
|
||||||
session.SendMsg(string(this.module.GetType()), GetlistResp, code, &pb.GetlistResp{Grids: grids})
|
session.SendMsg(string(this.module.GetType()), GetlistResp, code, &pb.GetlistResp{Grids: grids})
|
||||||
|
if code == pb.ErrorCode_Success {
|
||||||
|
go func() { //异步处理修改数据
|
||||||
|
cache.Defsys.Pack_UpdateGridToUserPack(session.GetUserId(), modifys...)
|
||||||
}()
|
}()
|
||||||
if !session.IsLogin() {
|
}
|
||||||
code = pb.ErrorCode_NoLogin
|
}()
|
||||||
|
if code = this.Getlist_Check(ctx, session, req); code != pb.ErrorCode_Success {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if pack, err = cache.Defsys.Pack_QueryUserPack(session.GetUserId()); err != nil {
|
if pack, err = cache.Defsys.Pack_QueryUserPack(session.GetUserId()); err != nil {
|
||||||
@ -27,7 +44,21 @@ func (this *Api_Comp) Getlist(ctx context.Context, session comm.IUserSession, re
|
|||||||
code = pb.ErrorCode_CacheReadError
|
code = pb.ErrorCode_CacheReadError
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
grids = this.module.configure_comp.GetPackItemByType(pack, req.IType)
|
tempgrids = this.module.configure_comp.GetPackItemByType(pack, req.IType)
|
||||||
|
modifys = make([]*pb.DB_GridData, 0, len(tempgrids))
|
||||||
|
grids = make([]*pb.DB_GridData, 0, len(grids))
|
||||||
|
nt = time.Now().Unix()
|
||||||
|
for _, v := range tempgrids {
|
||||||
|
if v.ETime > 0 && v.ETime < nt { //已经过期
|
||||||
|
modifys = append(modifys, &pb.DB_GridData{GridId: v.GridId, IsEmpty: true})
|
||||||
|
} else {
|
||||||
|
grids = append(grids, v)
|
||||||
|
if v.IsNewItem {
|
||||||
|
v.IsNewItem = false
|
||||||
|
modifys = append(modifys, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,15 @@ import (
|
|||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//参数校验
|
||||||
|
func (this *Api_Comp) SellItem_Check(ctx context.Context, session comm.IUserSession, req *pb.SellItemReq) (code pb.ErrorCode) {
|
||||||
|
if !session.IsLogin() {
|
||||||
|
code = pb.ErrorCode_NoLogin
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
//出售道具
|
//出售道具
|
||||||
func (this *Api_Comp) SellItem(ctx context.Context, session comm.IUserSession, req *pb.SellItemReq) (err error) {
|
func (this *Api_Comp) SellItem(ctx context.Context, session comm.IUserSession, req *pb.SellItemReq) (err error) {
|
||||||
var (
|
var (
|
||||||
@ -14,8 +23,7 @@ func (this *Api_Comp) SellItem(ctx context.Context, session comm.IUserSession, r
|
|||||||
defer func() {
|
defer func() {
|
||||||
session.SendMsg(string(this.module.GetType()), SellItemResp, code, &pb.SellItemResp{})
|
session.SendMsg(string(this.module.GetType()), SellItemResp, code, &pb.SellItemResp{})
|
||||||
}()
|
}()
|
||||||
if !session.IsLogin() {
|
if code = this.SellItem_Check(ctx, session, req); code != pb.ErrorCode_Success {
|
||||||
code = pb.ErrorCode_NoLogin
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -6,6 +6,15 @@ import (
|
|||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//参数校验
|
||||||
|
func (this *Api_Comp) Useitem_Check(ctx context.Context, session comm.IUserSession, req *pb.UseItemReq) (code pb.ErrorCode) {
|
||||||
|
if !session.IsLogin() {
|
||||||
|
code = pb.ErrorCode_NoLogin
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
//使用道具
|
//使用道具
|
||||||
func (this *Api_Comp) Useitem(ctx context.Context, session comm.IUserSession, req *pb.UseItemReq) (err error) {
|
func (this *Api_Comp) Useitem(ctx context.Context, session comm.IUserSession, req *pb.UseItemReq) (err error) {
|
||||||
var (
|
var (
|
||||||
@ -14,8 +23,7 @@ func (this *Api_Comp) Useitem(ctx context.Context, session comm.IUserSession, re
|
|||||||
defer func() {
|
defer func() {
|
||||||
session.SendMsg(string(this.module.GetType()), UseItemResp, code, &pb.UseItemResp{})
|
session.SendMsg(string(this.module.GetType()), UseItemResp, code, &pb.UseItemResp{})
|
||||||
}()
|
}()
|
||||||
if !session.IsLogin() {
|
if code = this.Useitem_Check(ctx, session, req); code != pb.ErrorCode_Success {
|
||||||
code = pb.ErrorCode_NoLogin
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
288
modules/pack/cache_comp.go
Normal file
288
modules/pack/cache_comp.go
Normal file
@ -0,0 +1,288 @@
|
|||||||
|
package pack
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"go_dreamfactory/lego/core/cbase"
|
||||||
|
"go_dreamfactory/lego/sys/mgo"
|
||||||
|
"go_dreamfactory/lego/sys/redis"
|
||||||
|
"go_dreamfactory/pb"
|
||||||
|
"go_dreamfactory/sys/db"
|
||||||
|
)
|
||||||
|
|
||||||
|
///背包缓存数据管理组件
|
||||||
|
type Cache_Comp struct {
|
||||||
|
cbase.ModuleCompBase
|
||||||
|
redis redis.ISys
|
||||||
|
}
|
||||||
|
|
||||||
|
///查询用户背包数据
|
||||||
|
func (this *Cache_Comp) Pack_QueryUserPack(uId string) (pack *pb.DB_UserPackData, err error) {
|
||||||
|
pack = &pb.DB_UserPackData{
|
||||||
|
UserId: uId,
|
||||||
|
}
|
||||||
|
if err = this.redis.Get(fmt.Sprintf(Redis_PackCache, uId), pack); err == nil {
|
||||||
|
return
|
||||||
|
} else if err == redis.RedisNil {
|
||||||
|
if pack, err = db.Defsys.Pack_QueryUserPack(uId); err == nil {
|
||||||
|
this.redis.Set(fmt.Sprintf(Redis_PackCache, uId), pack, Pack_Expiration)
|
||||||
|
} else if err == mgo.MongodbNil {
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询用户背包物品数量
|
||||||
|
func (this *Cache_Comp) Pack_QueryUserPackItemAmount(uId string, itemid int32) (amount uint32) {
|
||||||
|
var (
|
||||||
|
pack *pb.DB_UserPackData
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
if pack, err = this.Pack_QueryUserPack(uId); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, v := range pack.Pack {
|
||||||
|
if !v.IsEmpty && v.ItemId == itemid {
|
||||||
|
amount += v.Amount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
///添加或则减少物品到用户背包
|
||||||
|
func (this *Cache_Comp) Pack_AddItemToUserPack(uId string, itemId int32, addnum int32) (err error) {
|
||||||
|
var (
|
||||||
|
pack *pb.DB_UserPackData
|
||||||
|
modifys []*pb.DB_GridData
|
||||||
|
leftnum int64
|
||||||
|
)
|
||||||
|
if addnum == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if pack, err = this.Pack_QueryUserPack(uId); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
modifys, leftnum = this.pack_addItemToUserPack(pack, itemId, addnum)
|
||||||
|
if leftnum < 0 {
|
||||||
|
err = ItemNotEnoughError
|
||||||
|
return
|
||||||
|
} else if leftnum > 0 {
|
||||||
|
err = PackGridNumUpper
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if pack, err = db.Defsys.Pack_UpdateGridToUserPack(uId, modifys...); err == nil {
|
||||||
|
this.redis.Set(fmt.Sprintf(Redis_PackCache, uId), pack, Pack_Expiration)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
///添加或则减少多个物品到用户背包
|
||||||
|
func (this *Cache_Comp) Pack_AddItemsToUserPack(uId string, items map[int32]int32) (err error) {
|
||||||
|
var (
|
||||||
|
pack *pb.DB_UserPackData
|
||||||
|
modifys []*pb.DB_GridData
|
||||||
|
tempmodifys []*pb.DB_GridData
|
||||||
|
leftnum int64
|
||||||
|
iskeep bool
|
||||||
|
)
|
||||||
|
if pack, err = this.Pack_QueryUserPack(uId); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for k, v := range items {
|
||||||
|
tempmodifys, leftnum = this.pack_addItemToUserPack(pack, k, v)
|
||||||
|
if leftnum < 0 {
|
||||||
|
err = ItemNotEnoughError
|
||||||
|
return
|
||||||
|
} else if leftnum > 0 {
|
||||||
|
err = PackGridNumUpper
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, v1 := range tempmodifys {
|
||||||
|
iskeep = false
|
||||||
|
for _, v2 := range modifys {
|
||||||
|
if v1.GridId == v2.GridId {
|
||||||
|
iskeep = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !iskeep {
|
||||||
|
modifys = append(modifys, v1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if pack, err = db.Defsys.Pack_UpdateGridToUserPack(uId, modifys...); err == nil {
|
||||||
|
this.redis.Set(fmt.Sprintf(Redis_PackCache, uId), pack, Pack_Expiration)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
///修改指定格子的物品数量
|
||||||
|
func (this *Cache_Comp) Pack_AddItemToUserPackByGrid(uId string, gridid int32, itemId int32, addnum int32) (err error) {
|
||||||
|
var (
|
||||||
|
pack *pb.DB_UserPackData
|
||||||
|
grid *pb.DB_GridData
|
||||||
|
num int64
|
||||||
|
amount int64
|
||||||
|
)
|
||||||
|
if addnum == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if pack, err = this.Pack_QueryUserPack(uId); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if int32(len(pack.Pack)) <= gridid {
|
||||||
|
err = NoFoundGirdError
|
||||||
|
return
|
||||||
|
}
|
||||||
|
grid = pack.Pack[gridid]
|
||||||
|
if grid == nil {
|
||||||
|
err = NoFoundGirdError
|
||||||
|
return
|
||||||
|
}
|
||||||
|
amount = int64(grid.Amount)
|
||||||
|
if grid.IsEmpty {
|
||||||
|
amount = 0
|
||||||
|
} else if grid.ItemId != itemId {
|
||||||
|
err = fmt.Errorf("target grid itemid:%d no is %d ", grid.ItemId, itemId)
|
||||||
|
}
|
||||||
|
num = amount + int64(addnum)
|
||||||
|
if num < 0 {
|
||||||
|
err = ItemNotEnoughError
|
||||||
|
} else {
|
||||||
|
if num > GridCapMaxNum {
|
||||||
|
err = GirdAmountUpper
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
if pack, err = db.Defsys.Pack_UpdateGridToUserPack(uId, grid); err == nil {
|
||||||
|
this.redis.Set(fmt.Sprintf(Redis_PackCache, uId), pack, Pack_Expiration)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
///修改目标格子的新获取标识
|
||||||
|
func (this *Cache_Comp) Pack_ModifyPackGridIsNewItem(uId string, grids []int32) (err error) {
|
||||||
|
var (
|
||||||
|
pack *pb.DB_UserPackData
|
||||||
|
)
|
||||||
|
if pack, err = db.Defsys.Pack_ModifyPackGridIsNewItem(uId, grids); err == nil {
|
||||||
|
err = this.redis.Set(fmt.Sprintf(Redis_PackCache, uId), pack, Pack_Expiration)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
///修改目标格子的新获取标识
|
||||||
|
func (this *Cache_Comp) Pack_UpdateGridToUserPack(uId string, grids ...*pb.DB_GridData) (err error) {
|
||||||
|
var (
|
||||||
|
pack *pb.DB_UserPackData
|
||||||
|
)
|
||||||
|
if pack, err = db.Defsys.Pack_UpdateGridToUserPack(uId, grids...); err == nil {
|
||||||
|
err = this.redis.Set(fmt.Sprintf(Redis_PackCache, uId), pack, Pack_Expiration)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
///添加移除物品到用户背包
|
||||||
|
func (this *Cache_Comp) pack_addItemToUserPack(pack *pb.DB_UserPackData, itemId int32, addnum int32) (modifys []*pb.DB_GridData, leftnum int64) {
|
||||||
|
var (
|
||||||
|
num int64
|
||||||
|
isNew bool
|
||||||
|
)
|
||||||
|
if addnum == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
isNew = true
|
||||||
|
leftnum = int64(addnum)
|
||||||
|
modifys = make([]*pb.DB_GridData, 0)
|
||||||
|
for _, v := range pack.Pack {
|
||||||
|
if !v.IsEmpty && v.ItemId == itemId {
|
||||||
|
isNew = false
|
||||||
|
num = int64(v.Amount) + int64(leftnum)
|
||||||
|
if num < 0 {
|
||||||
|
leftnum += int64(v.Amount)
|
||||||
|
v.Amount = 0
|
||||||
|
v.IsEmpty = true
|
||||||
|
modifys = append(modifys, v)
|
||||||
|
} else if num > 0 && num < int64(v.Amount) {
|
||||||
|
leftnum = 0
|
||||||
|
v.Amount = uint32(num)
|
||||||
|
modifys = append(modifys, v)
|
||||||
|
break
|
||||||
|
} else if num > 0 && num > int64(v.Amount) {
|
||||||
|
if num <= GridCapMaxNum {
|
||||||
|
leftnum = 0
|
||||||
|
v.Amount = uint32(num)
|
||||||
|
modifys = append(modifys, v)
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
if v.Amount < GridCapMaxNum {
|
||||||
|
leftnum = int64(num - GridCapMaxNum)
|
||||||
|
v.Amount = uint32(GridCapMaxNum)
|
||||||
|
modifys = append(modifys, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if num == 0 {
|
||||||
|
leftnum = 0
|
||||||
|
v.Amount = 0
|
||||||
|
v.IsEmpty = true
|
||||||
|
modifys = append(modifys, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if leftnum < 0 { //背包物品不够
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if leftnum > 0 { //还没有放完 寻找空的格子填充
|
||||||
|
for _, v := range pack.Pack {
|
||||||
|
if v.IsEmpty {
|
||||||
|
if leftnum <= GridCapMaxNum {
|
||||||
|
v.IsEmpty = false
|
||||||
|
v.ItemId = itemId
|
||||||
|
v.Amount = uint32(leftnum)
|
||||||
|
leftnum = 0
|
||||||
|
modifys = append(modifys, v)
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
leftnum -= GridCapMaxNum
|
||||||
|
v.IsEmpty = false
|
||||||
|
v.ItemId = itemId
|
||||||
|
v.Amount = uint32(GridCapMaxNum)
|
||||||
|
modifys = append(modifys, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
index := int32(len(pack.Pack))
|
||||||
|
for leftnum > 0 { //需要补充格子
|
||||||
|
if leftnum <= GridCapMaxNum {
|
||||||
|
grid := &pb.DB_GridData{
|
||||||
|
GridId: index,
|
||||||
|
IsEmpty: false,
|
||||||
|
ItemId: itemId,
|
||||||
|
Amount: uint32(leftnum),
|
||||||
|
IsNewItem: isNew,
|
||||||
|
}
|
||||||
|
pack.Pack = append(pack.Pack, grid)
|
||||||
|
modifys = append(modifys, grid)
|
||||||
|
leftnum = 0
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
leftnum -= GridCapMaxNum
|
||||||
|
grid := &pb.DB_GridData{
|
||||||
|
GridId: index,
|
||||||
|
IsEmpty: false,
|
||||||
|
ItemId: itemId,
|
||||||
|
Amount: uint32(GridCapMaxNum),
|
||||||
|
IsNewItem: isNew,
|
||||||
|
}
|
||||||
|
pack.Pack = append(pack.Pack, grid)
|
||||||
|
modifys = append(modifys, grid)
|
||||||
|
index++
|
||||||
|
}
|
||||||
|
if index > GridMaxNUm { //格子已达上限
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
@ -60,6 +60,7 @@ func (this *Configure_Comp) GetPackItemByType(pack *pb.DB_UserPackData, usetype
|
|||||||
} else {
|
} else {
|
||||||
table = v.(*cfg.Game_item)
|
table = v.(*cfg.Game_item)
|
||||||
for _, v := range pack.Pack {
|
for _, v := range pack.Pack {
|
||||||
|
if !v.IsEmpty {
|
||||||
if item, ok = table.GetDataMap()[id]; ok {
|
if item, ok = table.GetDataMap()[id]; ok {
|
||||||
if item.Usetype == usetype {
|
if item.Usetype == usetype {
|
||||||
result = append(result, v)
|
result = append(result, v)
|
||||||
@ -69,5 +70,6 @@ func (this *Configure_Comp) GetPackItemByType(pack *pb.DB_UserPackData, usetype
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,24 @@
|
|||||||
package pack
|
package pack
|
||||||
|
|
||||||
import "go_dreamfactory/modules"
|
import (
|
||||||
|
"errors"
|
||||||
type (
|
"go_dreamfactory/lego/core"
|
||||||
IPack interface {
|
)
|
||||||
modules.IModule
|
|
||||||
}
|
const ( //Redis
|
||||||
IConfigure_Comp interface {
|
Redis_PackCache string = "pack:%s" //背包缓存数据存放key
|
||||||
}
|
DB_PackTable core.SqlTable = "pack" //背包数据库定义表
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
GridCapMaxNum = 99 //单个格子的最大容量
|
||||||
|
GridMaxNUm = 200 //背包格子数量上限
|
||||||
|
Pack_Expiration = -1 //背包缓存数据过期时间
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ItemNotEnoughError = errors.New("item not enough!") //物品不足
|
||||||
|
NoFoundGirdError = errors.New("no found gvrid!") //未找到格子
|
||||||
|
PackGridNumUpper = errors.New("grid amount upper!") //背包格子达到上限
|
||||||
|
GirdAmountUpper = errors.New("grid amount upper!") //格子容量达到上限
|
||||||
)
|
)
|
||||||
|
73
modules/pack/db_comp.go
Normal file
73
modules/pack/db_comp.go
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
package pack
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"go_dreamfactory/lego/core/cbase"
|
||||||
|
"go_dreamfactory/lego/sys/mgo"
|
||||||
|
"go_dreamfactory/pb"
|
||||||
|
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
|
)
|
||||||
|
|
||||||
|
///背包数据库数据管理组件
|
||||||
|
type DB_Comp struct {
|
||||||
|
cbase.ModuleCompBase
|
||||||
|
mgo mgo.ISys
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *DB_Comp) Pack_InitUserPack(uId string) (pack *pb.DB_UserPackData, err error) {
|
||||||
|
pack = &pb.DB_UserPackData{UserId: uId, Pack: make([]*pb.DB_GridData, 0)}
|
||||||
|
_, err = this.mgo.InsertOne(DB_PackTable, pack)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
///查询用户背包数据
|
||||||
|
func (this *DB_Comp) Pack_QueryUserPack(uId string) (pack *pb.DB_UserPackData, err error) {
|
||||||
|
pack = &pb.DB_UserPackData{}
|
||||||
|
err = this.mgo.FindOne(DB_PackTable, bson.M{"_id": uId}).Decode(pack)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//更新背包格子数据
|
||||||
|
func (this *DB_Comp) Pack_UpdateGridToUserPack(uId string, grids ...*pb.DB_GridData) (pack *pb.DB_UserPackData, err error) {
|
||||||
|
pack = &pb.DB_UserPackData{}
|
||||||
|
update := bson.M{}
|
||||||
|
for _, v := range grids {
|
||||||
|
update[fmt.Sprintf("pack.%d.gridid", v.GridId)] = v.GridId
|
||||||
|
update[fmt.Sprintf("pack.%d.isempty", v.GridId)] = v.IsEmpty
|
||||||
|
update[fmt.Sprintf("pack.%d.itemid", v.GridId)] = v.ItemId
|
||||||
|
update[fmt.Sprintf("pack.%d.amount", v.GridId)] = v.Amount
|
||||||
|
update[fmt.Sprintf("pack.%d.isnewitem", v.GridId)] = v.IsNewItem
|
||||||
|
}
|
||||||
|
|
||||||
|
err = this.mgo.FindOneAndUpdate(DB_PackTable,
|
||||||
|
bson.M{"_id": uId},
|
||||||
|
bson.M{"$set": update},
|
||||||
|
options.FindOneAndUpdate().SetUpsert(true).SetReturnDocument(options.After)).Decode(pack)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//更新背包格子物品的数据
|
||||||
|
func (this *DB_Comp) Pack_AddGridAmountToUserPack(uId string, grid int32, amount int32) (pack *pb.DB_UserPackData, err error) {
|
||||||
|
pack = &pb.DB_UserPackData{}
|
||||||
|
err = this.mgo.FindOneAndUpdate(DB_PackTable,
|
||||||
|
bson.M{"_id": uId},
|
||||||
|
bson.M{"$inc": bson.M{
|
||||||
|
fmt.Sprintf("pack.%d.amount", grid): amount,
|
||||||
|
}},
|
||||||
|
options.FindOneAndUpdate().SetUpsert(true).SetReturnDocument(options.After)).Decode(pack)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//修改背包格子IsNew标识
|
||||||
|
func (this *DB_Comp) Pack_ModifyPackGridIsNewItem(uId string, grids []int32) (pack *pb.DB_UserPackData, err error) {
|
||||||
|
pack = &pb.DB_UserPackData{}
|
||||||
|
identifier := []interface{}{bson.M{"item.gridid": bson.M{"$in": grids}}}
|
||||||
|
err = this.mgo.FindOneAndUpdate(DB_PackTable,
|
||||||
|
bson.M{"_id": uId},
|
||||||
|
bson.M{"$set": bson.M{
|
||||||
|
"pack.$[item].isNewitem": false,
|
||||||
|
}}, options.FindOneAndUpdate().SetArrayFilters(options.ArrayFilters{Filters: identifier}).SetReturnDocument(options.After)).Decode(pack)
|
||||||
|
return
|
||||||
|
}
|
@ -46,10 +46,28 @@ func (this *Pack) OnInstallComp() {
|
|||||||
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp)
|
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//IPack-------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
///查询用户背包物品数量
|
||||||
|
func (this *Pack) QueryUserPackItemAmount(uId string, itemid int32) (amount uint32) {
|
||||||
|
defer log.Debugf("获取物品 uId:%s itemid:%d addnum:%d ", uId, itemid, amount)
|
||||||
|
amount = cache.Defsys.Pack_QueryUserPackItemAmount(uId, itemid)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
///添加单个物品到背包 (可以加物品和减物品)
|
||||||
|
func (this *Pack) AddItemToUserPack(uId string, itemid, addnum int32) (err error) {
|
||||||
|
defer log.Debugf("给用户添加物品 uId:%s itemid:%d addnum:%d issucc:%v", uId, itemid, addnum, err == nil)
|
||||||
|
if err = cache.Defsys.Pack_AddItemToUserPack(uId, itemid, addnum); err != nil {
|
||||||
|
log.Errorf("给用户添加物品 uId:%s itemid:%d addnum:%d err:%v", uId, itemid, addnum, err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
///添加多个物品到背包 (可以加物品和减物品)
|
///添加多个物品到背包 (可以加物品和减物品)
|
||||||
func (this *Pack) AddItemsToUserPack(uId string, items map[int32]int32) (err error) {
|
func (this *Pack) AddItemsToUserPack(uId string, items map[int32]int32) (err error) {
|
||||||
|
defer log.Debugf("给用户添加物品 uId:%s items:%d items:%v", uId, items, err == nil)
|
||||||
if err = cache.Defsys.Pack_AddItemsToUserPack(uId, items); err != nil {
|
if err = cache.Defsys.Pack_AddItemsToUserPack(uId, items); err != nil {
|
||||||
log.Errorf("AddItemsToUserPack err:%v", err)
|
log.Errorf("给用户添加物品 uId:%s items:%d err:%v", uId, items, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -38,8 +38,8 @@ func decodeUserData(base64Str string) *pb.DB_UserData {
|
|||||||
}
|
}
|
||||||
account := jsonRet.Get("account").String()
|
account := jsonRet.Get("account").String()
|
||||||
return &pb.DB_UserData{
|
return &pb.DB_UserData{
|
||||||
ServerId: int32(serverId),
|
Sid: int32(serverId),
|
||||||
Account: account,
|
Binduid: account,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ func (this *LoginComp) Login(ctx context.Context, session comm.IUserSession, req
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
event.TriggerEvent(comm.Event_UserLogin, db_user.UserId)
|
event.TriggerEvent(comm.Event_UserLogin, db_user.Uid)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if !utils.ValidSecretKey(req.Sec) {
|
if !utils.ValidSecretKey(req.Sec) {
|
||||||
@ -81,9 +81,9 @@ func (this *LoginComp) Login(ctx context.Context, session comm.IUserSession, req
|
|||||||
log.Errorf("User_CreateUser err %v", err)
|
log.Errorf("User_CreateUser err %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
session.Build(user.UserId)
|
session.Bind(user.Uid, this.S.GetId())
|
||||||
} else {
|
} else {
|
||||||
session.Build(db_user.UserId)
|
session.Bind(db_user.Uid, this.S.GetId())
|
||||||
}
|
}
|
||||||
|
|
||||||
cache_user := &pb.Cache_UserData{
|
cache_user := &pb.Cache_UserData{
|
||||||
|
@ -13,6 +13,10 @@ import (
|
|||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
User_SubType_Create = "create"
|
||||||
|
)
|
||||||
|
|
||||||
type UserComp struct {
|
type UserComp struct {
|
||||||
modules.MComp_GateComp
|
modules.MComp_GateComp
|
||||||
module *User
|
module *User
|
||||||
@ -26,11 +30,11 @@ func (this *UserComp) Init(service core.IService, module core.IModule, comp core
|
|||||||
|
|
||||||
//创角
|
//创角
|
||||||
func (this *UserComp) Create(ctx context.Context, session comm.IUserSession, req *pb.UserCreateReq) (err error) {
|
func (this *UserComp) Create(ctx context.Context, session comm.IUserSession, req *pb.UserCreateReq) (err error) {
|
||||||
defer utils.TraceFunc(session.GetUserId(), "user", "create", req, nil)
|
defer utils.TraceFunc(session.GetUserId(), string(this.module.GetType()), User_SubType_Create, req, nil)
|
||||||
user := cache.Defsys.Get(session.GetUserId())
|
user := cache.Defsys.Get(session.GetUserId())
|
||||||
var code pb.ErrorCode
|
var code pb.ErrorCode
|
||||||
defer func() {
|
defer func() {
|
||||||
session.SendMsg("user", "create", code, &pb.UserCreateRsp{})
|
session.SendMsg(string(this.module.GetType()), User_SubType_Create, code, &pb.UserCreateRsp{})
|
||||||
}()
|
}()
|
||||||
if user == nil {
|
if user == nil {
|
||||||
log.Errorf("user no exist")
|
log.Errorf("user no exist")
|
||||||
@ -38,10 +42,12 @@ func (this *UserComp) Create(ctx context.Context, session comm.IUserSession, req
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
user.UserData.NiceName = req.NickName
|
user.UserData.Name = req.NickName
|
||||||
err = cache.Defsys.Update(user)
|
err = cache.Defsys.Update(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("cache update err")
|
log.Errorf("cache update err")
|
||||||
|
code = pb.ErrorCode_DBError
|
||||||
|
return
|
||||||
}
|
}
|
||||||
event.RegisterGO(comm.Event_CreateUser, session.GetUserId())
|
event.RegisterGO(comm.Event_CreateUser, session.GetUserId())
|
||||||
return nil
|
return nil
|
||||||
|
@ -38,7 +38,7 @@ func (this *Api_Comp) Register(c *engine.Context) {
|
|||||||
err := c.BindJSON(&req)
|
err := c.BindJSON(&req)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err := db.Defsys.User_Create(&pb.DB_UserData{
|
err := db.Defsys.User_Create(&pb.DB_UserData{
|
||||||
Account: req.Account,
|
Binduid: req.Account,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("create user err: %v", err)
|
log.Errorf("create user err: %v", err)
|
||||||
|
1
pb.bat
1
pb.bat
@ -8,6 +8,7 @@ set SRC=%PROJECT_ROOT%\pb\proto
|
|||||||
set TAR=%PROJECT_ROOT%\pb
|
set TAR=%PROJECT_ROOT%\pb
|
||||||
|
|
||||||
protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import %SRC%\*.proto
|
protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import %SRC%\*.proto
|
||||||
|
protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import %SRC%\user\*.proto
|
||||||
protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import %SRC%\friend\*.proto
|
protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import %SRC%\friend\*.proto
|
||||||
protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import %SRC%\pack\*.proto
|
protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import %SRC%\pack\*.proto
|
||||||
protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import %SRC%\mail\*.proto
|
protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import %SRC%\mail\*.proto
|
||||||
|
170
pb/comm.pb.go
170
pb/comm.pb.go
@ -9,6 +9,7 @@ package pb
|
|||||||
import (
|
import (
|
||||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||||
|
anypb "google.golang.org/protobuf/types/known/anypb"
|
||||||
reflect "reflect"
|
reflect "reflect"
|
||||||
sync "sync"
|
sync "sync"
|
||||||
)
|
)
|
||||||
@ -29,7 +30,7 @@ type UserMessage struct {
|
|||||||
MainType string `protobuf:"bytes,1,opt,name=MainType,proto3" json:"MainType,omitempty"`
|
MainType string `protobuf:"bytes,1,opt,name=MainType,proto3" json:"MainType,omitempty"`
|
||||||
SubType string `protobuf:"bytes,2,opt,name=SubType,proto3" json:"SubType,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"`
|
Code ErrorCode `protobuf:"varint,3,opt,name=Code,proto3,enum=ErrorCode" json:"Code,omitempty"`
|
||||||
Data []byte `protobuf:"bytes,4,opt,name=Data,proto3" json:"Data,omitempty"`
|
Data *anypb.Any `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *UserMessage) Reset() {
|
func (x *UserMessage) Reset() {
|
||||||
@ -85,7 +86,7 @@ func (x *UserMessage) GetCode() ErrorCode {
|
|||||||
return ErrorCode_Success
|
return ErrorCode_Success
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *UserMessage) GetData() []byte {
|
func (x *UserMessage) GetData() *anypb.Any {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.Data
|
return x.Data
|
||||||
}
|
}
|
||||||
@ -103,7 +104,7 @@ type AgentMessage struct {
|
|||||||
UserId string `protobuf:"bytes,3,opt,name=UserId,proto3" json:"UserId,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"`
|
GatewayServiceId string `protobuf:"bytes,4,opt,name=GatewayServiceId,proto3" json:"GatewayServiceId,omitempty"`
|
||||||
Method string `protobuf:"bytes,5,opt,name=Method,proto3" json:"Method,omitempty"`
|
Method string `protobuf:"bytes,5,opt,name=Method,proto3" json:"Method,omitempty"`
|
||||||
Message []byte `protobuf:"bytes,6,opt,name=Message,proto3" json:"Message,omitempty"`
|
Message *anypb.Any `protobuf:"bytes,6,opt,name=Message,proto3" json:"Message,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *AgentMessage) Reset() {
|
func (x *AgentMessage) Reset() {
|
||||||
@ -173,7 +174,7 @@ func (x *AgentMessage) GetMethod() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *AgentMessage) GetMessage() []byte {
|
func (x *AgentMessage) GetMessage() *anypb.Any {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.Message
|
return x.Message
|
||||||
}
|
}
|
||||||
@ -350,7 +351,7 @@ type AgentSendMessageReq struct {
|
|||||||
MainType string `protobuf:"bytes,2,opt,name=MainType,proto3" json:"MainType,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"`
|
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"`
|
Code ErrorCode `protobuf:"varint,4,opt,name=Code,proto3,enum=ErrorCode" json:"Code,omitempty"`
|
||||||
Data []byte `protobuf:"bytes,5,opt,name=Data,proto3" json:"Data,omitempty"`
|
Data *anypb.Any `protobuf:"bytes,5,opt,name=Data,proto3" json:"Data,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *AgentSendMessageReq) Reset() {
|
func (x *AgentSendMessageReq) Reset() {
|
||||||
@ -413,7 +414,7 @@ func (x *AgentSendMessageReq) GetCode() ErrorCode {
|
|||||||
return ErrorCode_Success
|
return ErrorCode_Success
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *AgentSendMessageReq) GetData() []byte {
|
func (x *AgentSendMessageReq) GetData() *anypb.Any {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.Data
|
return x.Data
|
||||||
}
|
}
|
||||||
@ -429,7 +430,7 @@ type BatchMessageReq struct {
|
|||||||
UserSessionIds []string `protobuf:"bytes,1,rep,name=UserSessionIds,proto3" json:"UserSessionIds,omitempty"`
|
UserSessionIds []string `protobuf:"bytes,1,rep,name=UserSessionIds,proto3" json:"UserSessionIds,omitempty"`
|
||||||
MainType string `protobuf:"bytes,2,opt,name=MainType,proto3" json:"MainType,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"`
|
SubType string `protobuf:"bytes,3,opt,name=SubType,proto3" json:"SubType,omitempty"`
|
||||||
Data []byte `protobuf:"bytes,4,opt,name=Data,proto3" json:"Data,omitempty"`
|
Data *anypb.Any `protobuf:"bytes,4,opt,name=Data,proto3" json:"Data,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *BatchMessageReq) Reset() {
|
func (x *BatchMessageReq) Reset() {
|
||||||
@ -485,7 +486,7 @@ func (x *BatchMessageReq) GetSubType() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *BatchMessageReq) GetData() []byte {
|
func (x *BatchMessageReq) GetData() *anypb.Any {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.Data
|
return x.Data
|
||||||
}
|
}
|
||||||
@ -500,7 +501,7 @@ type BroadCastMessageReq struct {
|
|||||||
|
|
||||||
MainType string `protobuf:"bytes,1,opt,name=MainType,proto3" json:"MainType,omitempty"` //服务名
|
MainType string `protobuf:"bytes,1,opt,name=MainType,proto3" json:"MainType,omitempty"` //服务名
|
||||||
SubType string `protobuf:"bytes,2,opt,name=SubType,proto3" json:"SubType,omitempty"`
|
SubType string `protobuf:"bytes,2,opt,name=SubType,proto3" json:"SubType,omitempty"`
|
||||||
Data []byte `protobuf:"bytes,3,opt,name=Data,proto3" json:"Data,omitempty"`
|
Data *anypb.Any `protobuf:"bytes,3,opt,name=Data,proto3" json:"Data,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *BroadCastMessageReq) Reset() {
|
func (x *BroadCastMessageReq) Reset() {
|
||||||
@ -549,7 +550,7 @@ func (x *BroadCastMessageReq) GetSubType() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *BroadCastMessageReq) GetData() []byte {
|
func (x *BroadCastMessageReq) GetData() *anypb.Any {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.Data
|
return x.Data
|
||||||
}
|
}
|
||||||
@ -608,69 +609,78 @@ var File_comm_proto protoreflect.FileDescriptor
|
|||||||
|
|
||||||
var file_comm_proto_rawDesc = []byte{
|
var file_comm_proto_rawDesc = []byte{
|
||||||
0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0f, 0x65, 0x72,
|
0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0f, 0x65, 0x72,
|
||||||
0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x77, 0x0a,
|
0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x19, 0x67,
|
||||||
0x0b, 0x55, 0x73, 0x65, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1a, 0x0a, 0x08,
|
0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x61,
|
||||||
0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08,
|
0x6e, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x8d, 0x01, 0x0a, 0x0b, 0x55, 0x73, 0x65,
|
||||||
0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x53, 0x75, 0x62, 0x54,
|
0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x4d, 0x61, 0x69, 0x6e,
|
||||||
0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79,
|
0x54, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4d, 0x61, 0x69, 0x6e,
|
||||||
0x70, 0x65, 0x12, 0x1e, 0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e,
|
0x54, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x18,
|
||||||
0x32, 0x0a, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x43, 0x6f,
|
0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e,
|
||||||
0x64, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c,
|
0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0a, 0x2e, 0x45,
|
||||||
0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0xba, 0x01, 0x0a, 0x0c, 0x41, 0x67, 0x65, 0x6e, 0x74,
|
0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x28,
|
||||||
0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x70, 0x18, 0x01, 0x20,
|
0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67,
|
||||||
0x01, 0x28, 0x09, 0x52, 0x02, 0x49, 0x70, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53,
|
0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41,
|
||||||
0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d,
|
0x6e, 0x79, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0xd0, 0x01, 0x0a, 0x0c, 0x41, 0x67, 0x65,
|
||||||
0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x16, 0x0a,
|
0x6e, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x70, 0x18,
|
||||||
0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x55,
|
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x49, 0x70, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65,
|
||||||
0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x2a, 0x0a, 0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79,
|
0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
|
||||||
0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52,
|
|
||||||
0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49,
|
|
||||||
0x64, 0x12, 0x16, 0x0a, 0x06, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28,
|
|
||||||
0x09, 0x52, 0x06, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x4d, 0x65, 0x73,
|
|
||||||
0x73, 0x61, 0x67, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x4d, 0x65, 0x73, 0x73,
|
|
||||||
0x61, 0x67, 0x65, 0x22, 0x43, 0x0a, 0x0f, 0x52, 0x50, 0x43, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67,
|
|
||||||
0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 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, 0x12, 0x10, 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x18, 0x02, 0x20,
|
|
||||||
0x01, 0x28, 0x09, 0x52, 0x03, 0x4d, 0x73, 0x67, 0x22, 0x4d, 0x0a, 0x0d, 0x41, 0x67, 0x65, 0x6e,
|
|
||||||
0x74, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65,
|
|
||||||
0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
|
|
||||||
0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12,
|
0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12,
|
||||||
0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
|
0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||||
0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, 0x37, 0x0a, 0x0f, 0x41, 0x67, 0x65, 0x6e, 0x74,
|
0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x2a, 0x0a, 0x10, 0x47, 0x61, 0x74, 0x65, 0x77,
|
||||||
0x55, 0x6e, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73,
|
0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28,
|
||||||
0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
|
0x09, 0x52, 0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63,
|
||||||
0x09, 0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64,
|
0x65, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x05, 0x20,
|
||||||
0x22, 0xa5, 0x01, 0x0a, 0x13, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x53, 0x65, 0x6e, 0x64, 0x4d, 0x65,
|
0x01, 0x28, 0x09, 0x52, 0x06, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x2e, 0x0a, 0x07, 0x4d,
|
||||||
0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72,
|
0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67,
|
||||||
0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
|
0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41,
|
||||||
0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x1a,
|
0x6e, 0x79, 0x52, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x43, 0x0a, 0x0f, 0x52,
|
||||||
0x0a, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
|
0x50, 0x43, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x1e,
|
||||||
0x52, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x53, 0x75,
|
0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0a, 0x2e, 0x45,
|
||||||
0x62, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x53, 0x75, 0x62,
|
0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x10,
|
||||||
0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x04, 0x20, 0x01,
|
0x0a, 0x03, 0x4d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x4d, 0x73, 0x67,
|
||||||
0x28, 0x0e, 0x32, 0x0a, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x04,
|
0x22, 0x4d, 0x0a, 0x0d, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x52, 0x65,
|
||||||
0x43, 0x6f, 0x64, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x05, 0x20, 0x01,
|
|
||||||
0x28, 0x0c, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0x83, 0x01, 0x0a, 0x0f, 0x42, 0x61, 0x74,
|
|
||||||
0x63, 0x68, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x12, 0x26, 0x0a, 0x0e,
|
|
||||||
0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x73, 0x18, 0x01,
|
|
||||||
0x20, 0x03, 0x28, 0x09, 0x52, 0x0e, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f,
|
|
||||||
0x6e, 0x49, 0x64, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65,
|
|
||||||
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65,
|
|
||||||
0x12, 0x18, 0x0a, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28,
|
|
||||||
0x09, 0x52, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x44, 0x61,
|
|
||||||
0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0x5f,
|
|
||||||
0x0a, 0x13, 0x42, 0x72, 0x6f, 0x61, 0x64, 0x43, 0x61, 0x73, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61,
|
|
||||||
0x67, 0x65, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70,
|
|
||||||
0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70,
|
|
||||||
0x65, 0x12, 0x18, 0x0a, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01,
|
|
||||||
0x28, 0x09, 0x52, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x44,
|
|
||||||
0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22,
|
|
||||||
0x36, 0x0a, 0x0e, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x65, 0x52, 0x65,
|
|
||||||
0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e,
|
0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e,
|
||||||
0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65,
|
0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65,
|
||||||
0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62,
|
0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49,
|
||||||
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22,
|
||||||
|
0x37, 0x0a, 0x0f, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x55, 0x6e, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x52,
|
||||||
|
0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f,
|
||||||
|
0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53,
|
||||||
|
0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x22, 0xbb, 0x01, 0x0a, 0x13, 0x41, 0x67, 0x65,
|
||||||
|
0x6e, 0x74, 0x53, 0x65, 0x6e, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71,
|
||||||
|
0x12, 0x24, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49,
|
||||||
|
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73,
|
||||||
|
0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79,
|
||||||
|
0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79,
|
||||||
|
0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20,
|
||||||
|
0x01, 0x28, 0x09, 0x52, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x04,
|
||||||
|
0x43, 0x6f, 0x64, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0a, 0x2e, 0x45, 0x72, 0x72,
|
||||||
|
0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x28, 0x0a, 0x04,
|
||||||
|
0x44, 0x61, 0x74, 0x61, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f,
|
||||||
|
0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79,
|
||||||
|
0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0x99, 0x01, 0x0a, 0x0f, 0x42, 0x61, 0x74, 0x63, 0x68,
|
||||||
|
0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x12, 0x26, 0x0a, 0x0e, 0x55, 0x73,
|
||||||
|
0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03,
|
||||||
|
0x28, 0x09, 0x52, 0x0e, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49,
|
||||||
|
0x64, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02,
|
||||||
|
0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4d, 0x61, 0x69, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x18,
|
||||||
|
0x0a, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||||
|
0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12, 0x28, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61,
|
||||||
|
0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e,
|
||||||
|
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x04, 0x44, 0x61,
|
||||||
|
0x74, 0x61, 0x22, 0x75, 0x0a, 0x13, 0x42, 0x72, 0x6f, 0x61, 0x64, 0x43, 0x61, 0x73, 0x74, 0x4d,
|
||||||
|
0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x4d, 0x61, 0x69,
|
||||||
|
0x6e, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4d, 0x61, 0x69,
|
||||||
|
0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65,
|
||||||
|
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x53, 0x75, 0x62, 0x54, 0x79, 0x70, 0x65, 0x12,
|
||||||
|
0x28, 0x0a, 0x04, 0x44, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e,
|
||||||
|
0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e,
|
||||||
|
0x41, 0x6e, 0x79, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22, 0x36, 0x0a, 0x0e, 0x41, 0x67, 0x65,
|
||||||
|
0x6e, 0x74, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x65, 0x52, 0x65, 0x71, 0x12, 0x24, 0x0a, 0x0d, 0x55,
|
||||||
|
0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01,
|
||||||
|
0x28, 0x09, 0x52, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49,
|
||||||
|
0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||||
|
0x33,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -697,16 +707,22 @@ var file_comm_proto_goTypes = []interface{}{
|
|||||||
(*BroadCastMessageReq)(nil), // 7: BroadCastMessageReq
|
(*BroadCastMessageReq)(nil), // 7: BroadCastMessageReq
|
||||||
(*AgentCloseeReq)(nil), // 8: AgentCloseeReq
|
(*AgentCloseeReq)(nil), // 8: AgentCloseeReq
|
||||||
(ErrorCode)(0), // 9: ErrorCode
|
(ErrorCode)(0), // 9: ErrorCode
|
||||||
|
(*anypb.Any)(nil), // 10: google.protobuf.Any
|
||||||
}
|
}
|
||||||
var file_comm_proto_depIdxs = []int32{
|
var file_comm_proto_depIdxs = []int32{
|
||||||
9, // 0: UserMessage.Code:type_name -> ErrorCode
|
9, // 0: UserMessage.Code:type_name -> ErrorCode
|
||||||
9, // 1: RPCMessageReply.Code:type_name -> ErrorCode
|
10, // 1: UserMessage.data:type_name -> google.protobuf.Any
|
||||||
9, // 2: AgentSendMessageReq.Code:type_name -> ErrorCode
|
10, // 2: AgentMessage.Message:type_name -> google.protobuf.Any
|
||||||
3, // [3:3] is the sub-list for method output_type
|
9, // 3: RPCMessageReply.Code:type_name -> ErrorCode
|
||||||
3, // [3:3] is the sub-list for method input_type
|
9, // 4: AgentSendMessageReq.Code:type_name -> ErrorCode
|
||||||
3, // [3:3] is the sub-list for extension type_name
|
10, // 5: AgentSendMessageReq.Data:type_name -> google.protobuf.Any
|
||||||
3, // [3:3] is the sub-list for extension extendee
|
10, // 6: BatchMessageReq.Data:type_name -> google.protobuf.Any
|
||||||
0, // [0:3] is the sub-list for field type_name
|
10, // 7: BroadCastMessageReq.Data:type_name -> google.protobuf.Any
|
||||||
|
8, // [8:8] is the sub-list for method output_type
|
||||||
|
8, // [8:8] is the sub-list for method input_type
|
||||||
|
8, // [8:8] is the sub-list for extension type_name
|
||||||
|
8, // [8:8] is the sub-list for extension extendee
|
||||||
|
0, // [0:8] is the sub-list for field type_name
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { file_comm_proto_init() }
|
func init() { file_comm_proto_init() }
|
||||||
|
@ -50,6 +50,7 @@ const (
|
|||||||
ErrorCode_FriendSelfBlackYet ErrorCode = 1107 //已在自己黑名单中
|
ErrorCode_FriendSelfBlackYet ErrorCode = 1107 //已在自己黑名单中
|
||||||
ErrorCode_FriendTargetBlackYet ErrorCode = 1108 //已在对方的黑名单中
|
ErrorCode_FriendTargetBlackYet ErrorCode = 1108 //已在对方的黑名单中
|
||||||
ErrorCode_FriendApplyError ErrorCode = 1109 //申请失败
|
ErrorCode_FriendApplyError ErrorCode = 1109 //申请失败
|
||||||
|
ErrorCode_FriendBlackMax ErrorCode = 1110 //黑名单最大数量
|
||||||
)
|
)
|
||||||
|
|
||||||
// Enum value maps for ErrorCode.
|
// Enum value maps for ErrorCode.
|
||||||
@ -80,6 +81,7 @@ var (
|
|||||||
1107: "FriendSelfBlackYet",
|
1107: "FriendSelfBlackYet",
|
||||||
1108: "FriendTargetBlackYet",
|
1108: "FriendTargetBlackYet",
|
||||||
1109: "FriendApplyError",
|
1109: "FriendApplyError",
|
||||||
|
1110: "FriendBlackMax",
|
||||||
}
|
}
|
||||||
ErrorCode_value = map[string]int32{
|
ErrorCode_value = map[string]int32{
|
||||||
"Success": 0,
|
"Success": 0,
|
||||||
@ -107,6 +109,7 @@ var (
|
|||||||
"FriendSelfBlackYet": 1107,
|
"FriendSelfBlackYet": 1107,
|
||||||
"FriendTargetBlackYet": 1108,
|
"FriendTargetBlackYet": 1108,
|
||||||
"FriendApplyError": 1109,
|
"FriendApplyError": 1109,
|
||||||
|
"FriendBlackMax": 1110,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -141,7 +144,7 @@ var File_errorcode_proto protoreflect.FileDescriptor
|
|||||||
|
|
||||||
var file_errorcode_proto_rawDesc = []byte{
|
var file_errorcode_proto_rawDesc = []byte{
|
||||||
0x0a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74,
|
0x0a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74,
|
||||||
0x6f, 0x2a, 0x88, 0x04, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12,
|
0x6f, 0x2a, 0x9d, 0x04, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12,
|
||||||
0x0b, 0x0a, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x10, 0x00, 0x12, 0x11, 0x0a, 0x0d,
|
0x0b, 0x0a, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x10, 0x00, 0x12, 0x11, 0x0a, 0x0d,
|
||||||
0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x10, 0x0a, 0x12,
|
0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x10, 0x0a, 0x12,
|
||||||
0x19, 0x0a, 0x15, 0x52, 0x70, 0x63, 0x46, 0x75, 0x6e, 0x63, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74,
|
0x19, 0x0a, 0x15, 0x52, 0x70, 0x63, 0x46, 0x75, 0x6e, 0x63, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74,
|
||||||
@ -173,8 +176,10 @@ var file_errorcode_proto_rawDesc = []byte{
|
|||||||
0x6c, 0x61, 0x63, 0x6b, 0x59, 0x65, 0x74, 0x10, 0xd3, 0x08, 0x12, 0x19, 0x0a, 0x14, 0x46, 0x72,
|
0x6c, 0x61, 0x63, 0x6b, 0x59, 0x65, 0x74, 0x10, 0xd3, 0x08, 0x12, 0x19, 0x0a, 0x14, 0x46, 0x72,
|
||||||
0x69, 0x65, 0x6e, 0x64, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x42, 0x6c, 0x61, 0x63, 0x6b, 0x59,
|
0x69, 0x65, 0x6e, 0x64, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x42, 0x6c, 0x61, 0x63, 0x6b, 0x59,
|
||||||
0x65, 0x74, 0x10, 0xd4, 0x08, 0x12, 0x15, 0x0a, 0x10, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x41,
|
0x65, 0x74, 0x10, 0xd4, 0x08, 0x12, 0x15, 0x0a, 0x10, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x41,
|
||||||
0x70, 0x70, 0x6c, 0x79, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0xd5, 0x08, 0x42, 0x06, 0x5a, 0x04,
|
0x70, 0x70, 0x6c, 0x79, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x10, 0xd5, 0x08, 0x12, 0x13, 0x0a, 0x0e,
|
||||||
0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, 0x6c, 0x61, 0x63, 0x6b, 0x4d, 0x61, 0x78, 0x10, 0xd6,
|
||||||
|
0x08, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||||
|
0x33,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -30,7 +30,9 @@ type DB_GridData struct {
|
|||||||
IsEmpty bool `protobuf:"varint,2,opt,name=IsEmpty,proto3" json:"IsEmpty,omitempty"` //是否是空格子
|
IsEmpty bool `protobuf:"varint,2,opt,name=IsEmpty,proto3" json:"IsEmpty,omitempty"` //是否是空格子
|
||||||
ItemId int32 `protobuf:"varint,3,opt,name=ItemId,proto3" json:"ItemId,omitempty"` //存放物品的Id
|
ItemId int32 `protobuf:"varint,3,opt,name=ItemId,proto3" json:"ItemId,omitempty"` //存放物品的Id
|
||||||
Amount uint32 `protobuf:"varint,4,opt,name=Amount,proto3" json:"Amount,omitempty"` //存放物品的数量
|
Amount uint32 `protobuf:"varint,4,opt,name=Amount,proto3" json:"Amount,omitempty"` //存放物品的数量
|
||||||
IsNewItem bool `protobuf:"varint,5,opt,name=IsNewItem,proto3" json:"IsNewItem,omitempty"` //是否是新的
|
CTime int64 `protobuf:"varint,5,opt,name=CTime,proto3" json:"CTime,omitempty"` //物品获取时间
|
||||||
|
ETime int64 `protobuf:"varint,6,opt,name=ETime,proto3" json:"ETime,omitempty"` //物品过期时间
|
||||||
|
IsNewItem bool `protobuf:"varint,7,opt,name=IsNewItem,proto3" json:"IsNewItem,omitempty"` //是否是新的
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *DB_GridData) Reset() {
|
func (x *DB_GridData) Reset() {
|
||||||
@ -93,6 +95,20 @@ func (x *DB_GridData) GetAmount() uint32 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *DB_GridData) GetCTime() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.CTime
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DB_GridData) GetETime() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.ETime
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
func (x *DB_GridData) GetIsNewItem() bool {
|
func (x *DB_GridData) GetIsNewItem() bool {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.IsNewItem
|
return x.IsNewItem
|
||||||
@ -160,22 +176,24 @@ var File_pack_pack_db_proto protoreflect.FileDescriptor
|
|||||||
|
|
||||||
var file_pack_pack_db_proto_rawDesc = []byte{
|
var file_pack_pack_db_proto_rawDesc = []byte{
|
||||||
0x0a, 0x12, 0x70, 0x61, 0x63, 0x6b, 0x2f, 0x70, 0x61, 0x63, 0x6b, 0x5f, 0x64, 0x62, 0x2e, 0x70,
|
0x0a, 0x12, 0x70, 0x61, 0x63, 0x6b, 0x2f, 0x70, 0x61, 0x63, 0x6b, 0x5f, 0x64, 0x62, 0x2e, 0x70,
|
||||||
0x72, 0x6f, 0x74, 0x6f, 0x22, 0x8d, 0x01, 0x0a, 0x0b, 0x44, 0x42, 0x5f, 0x47, 0x72, 0x69, 0x64,
|
0x72, 0x6f, 0x74, 0x6f, 0x22, 0xb9, 0x01, 0x0a, 0x0b, 0x44, 0x42, 0x5f, 0x47, 0x72, 0x69, 0x64,
|
||||||
0x44, 0x61, 0x74, 0x61, 0x12, 0x16, 0x0a, 0x06, 0x47, 0x72, 0x69, 0x64, 0x49, 0x64, 0x18, 0x01,
|
0x44, 0x61, 0x74, 0x61, 0x12, 0x16, 0x0a, 0x06, 0x47, 0x72, 0x69, 0x64, 0x49, 0x64, 0x18, 0x01,
|
||||||
0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x47, 0x72, 0x69, 0x64, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07,
|
0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x47, 0x72, 0x69, 0x64, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07,
|
||||||
0x49, 0x73, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x49,
|
0x49, 0x73, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x49,
|
||||||
0x73, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x49, 0x74, 0x65, 0x6d, 0x49, 0x64,
|
0x73, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x49, 0x74, 0x65, 0x6d, 0x49, 0x64,
|
||||||
0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x49, 0x74, 0x65, 0x6d, 0x49, 0x64, 0x12, 0x16,
|
0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x49, 0x74, 0x65, 0x6d, 0x49, 0x64, 0x12, 0x16,
|
||||||
0x0a, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06,
|
0x0a, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06,
|
||||||
0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x49, 0x73, 0x4e, 0x65, 0x77, 0x49,
|
0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x43, 0x54, 0x69, 0x6d, 0x65, 0x18,
|
||||||
0x74, 0x65, 0x6d, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x49, 0x73, 0x4e, 0x65, 0x77,
|
0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x43, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05,
|
||||||
0x49, 0x74, 0x65, 0x6d, 0x22, 0x4b, 0x0a, 0x0f, 0x44, 0x42, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x50,
|
0x45, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x45, 0x54, 0x69,
|
||||||
0x61, 0x63, 0x6b, 0x44, 0x61, 0x74, 0x61, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49,
|
0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x49, 0x73, 0x4e, 0x65, 0x77, 0x49, 0x74, 0x65, 0x6d, 0x18,
|
||||||
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12,
|
0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x49, 0x73, 0x4e, 0x65, 0x77, 0x49, 0x74, 0x65, 0x6d,
|
||||||
0x20, 0x0a, 0x04, 0x50, 0x61, 0x63, 0x6b, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e,
|
0x22, 0x4b, 0x0a, 0x0f, 0x44, 0x42, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x50, 0x61, 0x63, 0x6b, 0x44,
|
||||||
0x44, 0x42, 0x5f, 0x47, 0x72, 0x69, 0x64, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x50, 0x61, 0x63,
|
0x61, 0x74, 0x61, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20,
|
||||||
0x6b, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
0x01, 0x28, 0x09, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x20, 0x0a, 0x04, 0x50,
|
||||||
0x33,
|
0x61, 0x63, 0x6b, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x44, 0x42, 0x5f, 0x47,
|
||||||
|
0x72, 0x69, 0x64, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x50, 0x61, 0x63, 0x6b, 0x42, 0x06, 0x5a,
|
||||||
|
0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
option go_package = ".;pb";
|
option go_package = ".;pb";
|
||||||
import "errorcode.proto";
|
import "errorcode.proto";
|
||||||
|
import "google/protobuf/any.proto";
|
||||||
|
|
||||||
//用户消息流结构
|
//用户消息流结构
|
||||||
message UserMessage {
|
message UserMessage {
|
||||||
string MainType =1;
|
string MainType =1;
|
||||||
string SubType = 2;
|
string SubType = 2;
|
||||||
ErrorCode Code = 3;
|
ErrorCode Code = 3;
|
||||||
bytes Data = 4;
|
google.protobuf.Any data = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
//代理用户转发消息结构
|
//代理用户转发消息结构
|
||||||
@ -17,7 +18,7 @@ message AgentMessage {
|
|||||||
string UserId = 3;
|
string UserId = 3;
|
||||||
string GatewayServiceId = 4;
|
string GatewayServiceId = 4;
|
||||||
string Method = 5;
|
string Method = 5;
|
||||||
bytes Message = 6;
|
google.protobuf.Any Message = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
//RPC 服务固定回复结构
|
//RPC 服务固定回复结构
|
||||||
@ -42,7 +43,7 @@ message AgentSendMessageReq {
|
|||||||
string MainType = 2;
|
string MainType = 2;
|
||||||
string SubType = 3;
|
string SubType = 3;
|
||||||
ErrorCode Code = 4;
|
ErrorCode Code = 4;
|
||||||
bytes Data = 5;
|
google.protobuf.Any Data = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
//发送批量消息
|
//发送批量消息
|
||||||
@ -50,14 +51,14 @@ message BatchMessageReq {
|
|||||||
repeated string UserSessionIds = 1;
|
repeated string UserSessionIds = 1;
|
||||||
string MainType = 2;
|
string MainType = 2;
|
||||||
string SubType = 3;
|
string SubType = 3;
|
||||||
bytes Data = 4;
|
google.protobuf.Any Data = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
//发送广播消息
|
//发送广播消息
|
||||||
message BroadCastMessageReq {
|
message BroadCastMessageReq {
|
||||||
string MainType = 1; //服务名
|
string MainType = 1; //服务名
|
||||||
string SubType = 2;
|
string SubType = 2;
|
||||||
bytes Data = 3;
|
google.protobuf.Any Data = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
//关闭用户代理
|
//关闭用户代理
|
||||||
|
@ -32,4 +32,5 @@ enum ErrorCode {
|
|||||||
FriendSelfBlackYet = 1107;//已在自己黑名单中
|
FriendSelfBlackYet = 1107;//已在自己黑名单中
|
||||||
FriendTargetBlackYet = 1108;//已在对方的黑名单中
|
FriendTargetBlackYet = 1108;//已在对方的黑名单中
|
||||||
FriendApplyError = 1109;//申请失败
|
FriendApplyError = 1109;//申请失败
|
||||||
|
FriendBlackMax = 1110; //黑名单最大数量
|
||||||
}
|
}
|
@ -1,6 +1,5 @@
|
|||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
option go_package = ".;pb";
|
option go_package = ".;pb";
|
||||||
import "friend/friend_db.proto";
|
|
||||||
|
|
||||||
message FriendBase {
|
message FriendBase {
|
||||||
string userId = 1; //ID
|
string userId = 1; //ID
|
||||||
@ -18,7 +17,7 @@ message FriendListReq{
|
|||||||
}
|
}
|
||||||
|
|
||||||
message FriendListRsp{
|
message FriendListRsp{
|
||||||
repeated Cache_FriendData list = 1;
|
repeated FriendBase list = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//申请好友
|
//申请好友
|
||||||
@ -41,15 +40,20 @@ message FriendDelRsp{
|
|||||||
string userId = 2; //用户ID
|
string userId = 2; //用户ID
|
||||||
}
|
}
|
||||||
|
|
||||||
//同意或拒绝
|
//同意
|
||||||
message FriendAgreeOrRefuseReq{
|
message FriendAgreeReq{
|
||||||
string friendId = 1; //被同意或拒绝的用户
|
repeated string friendIds = 1; //被同意的用户
|
||||||
bool isAgree = 2;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
message FriendAgressOrRefuseRsp{
|
message FriendAgreeRsp{
|
||||||
|
int32 Num = 1;//操作的数量
|
||||||
|
}
|
||||||
|
|
||||||
|
//拒绝
|
||||||
|
message FriendRefuseReq{
|
||||||
|
repeated string friendIds = 1; //被拒绝的用户
|
||||||
|
}
|
||||||
|
message FriendRefuseRsp{
|
||||||
int32 Num = 1;//操作的数量
|
int32 Num = 1;//操作的数量
|
||||||
bool isAgree = 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -63,12 +67,11 @@ message FriendApplyListRsp{
|
|||||||
|
|
||||||
//好友搜索
|
//好友搜索
|
||||||
message FriendSearchReq{
|
message FriendSearchReq{
|
||||||
string friendId = 1;
|
string nickName = 1; //好友昵称
|
||||||
string nickName = 2; //好友昵称
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message FriendSearchRsp{
|
message FriendSearchRsp{
|
||||||
repeated FriendBase friends = 1;
|
FriendBase friend = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//黑名单
|
//黑名单
|
||||||
@ -90,18 +93,37 @@ message FriendBlackAddRsp{
|
|||||||
string userId = 2;
|
string userId = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
//赠送或接收
|
//删除黑名单
|
||||||
message FriendReceiveOrSendReq{
|
message FriendDelBlackReq{
|
||||||
string friendId = 1;
|
string friendId = 1;
|
||||||
bool isReceive = 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message FriendReceiveOrSendRsp{
|
message FriendDelBlackRsp{
|
||||||
string friendId = 1;
|
string friendId = 1;
|
||||||
string userId = 2;
|
string userId = 2;
|
||||||
bool isReceive = 3;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//接收
|
||||||
|
message FriendReceiveReq{
|
||||||
|
string friendId = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message FriendReceiveRsp{
|
||||||
|
string friendId = 1;
|
||||||
|
string userId = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
//赠送
|
||||||
|
message FriendGiveReq{
|
||||||
|
string friendId = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message FriendGiveRsp{
|
||||||
|
string friendId = 1;
|
||||||
|
string userId = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//好友数量
|
//好友数量
|
||||||
message FriendTotalReq{
|
message FriendTotalReq{
|
||||||
string friendId = 1;
|
string friendId = 1;
|
||||||
|
158
pb/proto/google/protobuf/any.proto
Normal file
158
pb/proto/google/protobuf/any.proto
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
// Protocol Buffers - Google's data interchange format
|
||||||
|
// Copyright 2008 Google Inc. All rights reserved.
|
||||||
|
// https://developers.google.com/protocol-buffers/
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions are
|
||||||
|
// met:
|
||||||
|
//
|
||||||
|
// * Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
// * Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following disclaimer
|
||||||
|
// in the documentation and/or other materials provided with the
|
||||||
|
// distribution.
|
||||||
|
// * Neither the name of Google Inc. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package google.protobuf;
|
||||||
|
|
||||||
|
option csharp_namespace = "Google.Protobuf.WellKnownTypes";
|
||||||
|
option go_package = "google.golang.org/protobuf/types/known/anypb";
|
||||||
|
option java_package = "com.google.protobuf";
|
||||||
|
option java_outer_classname = "AnyProto";
|
||||||
|
option java_multiple_files = true;
|
||||||
|
option objc_class_prefix = "GPB";
|
||||||
|
|
||||||
|
// `Any` contains an arbitrary serialized protocol buffer message along with a
|
||||||
|
// URL that describes the type of the serialized message.
|
||||||
|
//
|
||||||
|
// Protobuf library provides support to pack/unpack Any values in the form
|
||||||
|
// of utility functions or additional generated methods of the Any type.
|
||||||
|
//
|
||||||
|
// Example 1: Pack and unpack a message in C++.
|
||||||
|
//
|
||||||
|
// Foo foo = ...;
|
||||||
|
// Any any;
|
||||||
|
// any.PackFrom(foo);
|
||||||
|
// ...
|
||||||
|
// if (any.UnpackTo(&foo)) {
|
||||||
|
// ...
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Example 2: Pack and unpack a message in Java.
|
||||||
|
//
|
||||||
|
// Foo foo = ...;
|
||||||
|
// Any any = Any.pack(foo);
|
||||||
|
// ...
|
||||||
|
// if (any.is(Foo.class)) {
|
||||||
|
// foo = any.unpack(Foo.class);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Example 3: Pack and unpack a message in Python.
|
||||||
|
//
|
||||||
|
// foo = Foo(...)
|
||||||
|
// any = Any()
|
||||||
|
// any.Pack(foo)
|
||||||
|
// ...
|
||||||
|
// if any.Is(Foo.DESCRIPTOR):
|
||||||
|
// any.Unpack(foo)
|
||||||
|
// ...
|
||||||
|
//
|
||||||
|
// Example 4: Pack and unpack a message in Go
|
||||||
|
//
|
||||||
|
// foo := &pb.Foo{...}
|
||||||
|
// any, err := anypb.New(foo)
|
||||||
|
// if err != nil {
|
||||||
|
// ...
|
||||||
|
// }
|
||||||
|
// ...
|
||||||
|
// foo := &pb.Foo{}
|
||||||
|
// if err := any.UnmarshalTo(foo); err != nil {
|
||||||
|
// ...
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// The pack methods provided by protobuf library will by default use
|
||||||
|
// 'type.googleapis.com/full.type.name' as the type URL and the unpack
|
||||||
|
// methods only use the fully qualified type name after the last '/'
|
||||||
|
// in the type URL, for example "foo.bar.com/x/y.z" will yield type
|
||||||
|
// name "y.z".
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// JSON
|
||||||
|
//
|
||||||
|
// The JSON representation of an `Any` value uses the regular
|
||||||
|
// representation of the deserialized, embedded message, with an
|
||||||
|
// additional field `@type` which contains the type URL. Example:
|
||||||
|
//
|
||||||
|
// package google.profile;
|
||||||
|
// message Person {
|
||||||
|
// string first_name = 1;
|
||||||
|
// string last_name = 2;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// {
|
||||||
|
// "@type": "type.googleapis.com/google.profile.Person",
|
||||||
|
// "firstName": <string>,
|
||||||
|
// "lastName": <string>
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// If the embedded message type is well-known and has a custom JSON
|
||||||
|
// representation, that representation will be embedded adding a field
|
||||||
|
// `value` which holds the custom JSON in addition to the `@type`
|
||||||
|
// field. Example (for message [google.protobuf.Duration][]):
|
||||||
|
//
|
||||||
|
// {
|
||||||
|
// "@type": "type.googleapis.com/google.protobuf.Duration",
|
||||||
|
// "value": "1.212s"
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
message Any {
|
||||||
|
// A URL/resource name that uniquely identifies the type of the serialized
|
||||||
|
// protocol buffer message. This string must contain at least
|
||||||
|
// one "/" character. The last segment of the URL's path must represent
|
||||||
|
// the fully qualified name of the type (as in
|
||||||
|
// `path/google.protobuf.Duration`). The name should be in a canonical form
|
||||||
|
// (e.g., leading "." is not accepted).
|
||||||
|
//
|
||||||
|
// In practice, teams usually precompile into the binary all types that they
|
||||||
|
// expect it to use in the context of Any. However, for URLs which use the
|
||||||
|
// scheme `http`, `https`, or no scheme, one can optionally set up a type
|
||||||
|
// server that maps type URLs to message definitions as follows:
|
||||||
|
//
|
||||||
|
// * If no scheme is provided, `https` is assumed.
|
||||||
|
// * An HTTP GET on the URL must yield a [google.protobuf.Type][]
|
||||||
|
// value in binary format, or produce an error.
|
||||||
|
// * Applications are allowed to cache lookup results based on the
|
||||||
|
// URL, or have them precompiled into a binary to avoid any
|
||||||
|
// lookup. Therefore, binary compatibility needs to be preserved
|
||||||
|
// on changes to types. (Use versioned type names to manage
|
||||||
|
// breaking changes.)
|
||||||
|
//
|
||||||
|
// Note: this functionality is not currently available in the official
|
||||||
|
// protobuf release, and it is not used for type URLs beginning with
|
||||||
|
// type.googleapis.com.
|
||||||
|
//
|
||||||
|
// Schemes other than `http`, `https` (or the empty scheme) might be
|
||||||
|
// used with implementation specific semantics.
|
||||||
|
//
|
||||||
|
string type_url = 1;
|
||||||
|
|
||||||
|
// Must be a valid serialized protocol buffer of the above specified type.
|
||||||
|
bytes value = 2;
|
||||||
|
}
|
@ -8,7 +8,9 @@ message DB_GridData {
|
|||||||
bool IsEmpty = 2; //是否是空格子
|
bool IsEmpty = 2; //是否是空格子
|
||||||
int32 ItemId = 3; //存放物品的Id
|
int32 ItemId = 3; //存放物品的Id
|
||||||
uint32 Amount = 4; //存放物品的数量
|
uint32 Amount = 4; //存放物品的数量
|
||||||
bool IsNewItem = 5; //是否是新的
|
int64 CTime = 5; //物品获取时间
|
||||||
|
int64 ETime = 6; //物品过期时间
|
||||||
|
bool IsNewItem = 7; //是否是新的
|
||||||
}
|
}
|
||||||
|
|
||||||
//用户背包
|
//用户背包
|
||||||
|
@ -4,12 +4,12 @@ import "pack/pack_db.proto";
|
|||||||
|
|
||||||
//查询用户背包请求
|
//查询用户背包请求
|
||||||
message GetlistReq {
|
message GetlistReq {
|
||||||
int32 IType = 1;
|
int32 IType = 1; //道具类型
|
||||||
}
|
}
|
||||||
|
|
||||||
//查询用户背包请求 回应
|
//查询用户背包请求 回应
|
||||||
message GetlistResp {
|
message GetlistResp {
|
||||||
repeated DB_GridData Grids = 1;
|
repeated DB_GridData Grids = 1; //用户背包列表
|
||||||
}
|
}
|
||||||
|
|
||||||
//使用物品请求
|
//使用物品请求
|
||||||
|
@ -8,10 +8,16 @@ message Cache_UserData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message DB_UserData {
|
message DB_UserData {
|
||||||
string UserId = 1; //tags:{bson:"_id"}动态Id
|
string id = 1; // @go_tags(`bson:"_id"`) ID
|
||||||
string Account = 2;
|
string uid = 2;
|
||||||
string NiceName = 3;
|
string uuid = 3; //玩家唯一uuid
|
||||||
int32 ServerId = 4;
|
string binduid = 4; //玩家账号
|
||||||
int32 FriendPoint = 5;//友情点
|
string name = 5; //玩家名
|
||||||
int32 avatar = 6;//头像
|
int32 sid = 6; //区服id
|
||||||
|
string createip = 7; //创建账号时的ip
|
||||||
|
string lastloginip = 8; //最后一次登录时的ip
|
||||||
|
int64 ctime = 9; //玩家创号时间戳
|
||||||
|
int64 logintime = 10; //最后一次登录时间
|
||||||
|
int32 FriendPoint = 11; //友情点
|
||||||
|
int32 avatar = 12; //头像
|
||||||
}
|
}
|
110
pb/user_db.pb.go
110
pb/user_db.pb.go
@ -88,12 +88,18 @@ type DB_UserData struct {
|
|||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
UserId string `protobuf:"bytes,1,opt,name=UserId,proto3" json:"UserId,omitempty"` //tags:{bson:"_id"}动态Id
|
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty" bson:"_id"` // ID
|
||||||
Account string `protobuf:"bytes,2,opt,name=Account,proto3" json:"Account,omitempty"`
|
Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid,omitempty"`
|
||||||
NiceName string `protobuf:"bytes,3,opt,name=NiceName,proto3" json:"NiceName,omitempty"`
|
Uuid string `protobuf:"bytes,3,opt,name=uuid,proto3" json:"uuid,omitempty"` //玩家唯一uuid
|
||||||
ServerId int32 `protobuf:"varint,4,opt,name=ServerId,proto3" json:"ServerId,omitempty"`
|
Binduid string `protobuf:"bytes,4,opt,name=binduid,proto3" json:"binduid,omitempty"` //玩家账号
|
||||||
FriendPoint int32 `protobuf:"varint,5,opt,name=FriendPoint,proto3" json:"FriendPoint,omitempty"` //友情点
|
Name string `protobuf:"bytes,5,opt,name=name,proto3" json:"name,omitempty"` //玩家名
|
||||||
Avatar int32 `protobuf:"varint,6,opt,name=avatar,proto3" json:"avatar,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"` //头像
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *DB_UserData) Reset() {
|
func (x *DB_UserData) Reset() {
|
||||||
@ -128,30 +134,72 @@ func (*DB_UserData) Descriptor() ([]byte, []int) {
|
|||||||
return file_user_user_db_proto_rawDescGZIP(), []int{1}
|
return file_user_user_db_proto_rawDescGZIP(), []int{1}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *DB_UserData) GetUserId() string {
|
func (x *DB_UserData) GetId() string {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.UserId
|
return x.Id
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *DB_UserData) GetAccount() string {
|
func (x *DB_UserData) GetUid() string {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.Account
|
return x.Uid
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *DB_UserData) GetNiceName() string {
|
func (x *DB_UserData) GetUuid() string {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.NiceName
|
return x.Uuid
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *DB_UserData) GetServerId() int32 {
|
func (x *DB_UserData) GetBinduid() string {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.ServerId
|
return x.Binduid
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DB_UserData) GetName() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Name
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DB_UserData) GetSid() int32 {
|
||||||
|
if x != nil {
|
||||||
|
return x.Sid
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DB_UserData) GetCreateip() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Createip
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DB_UserData) GetLastloginip() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Lastloginip
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DB_UserData) GetCtime() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.Ctime
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DB_UserData) GetLogintime() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.Logintime
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@ -182,19 +230,27 @@ var file_user_user_db_proto_rawDesc = []byte{
|
|||||||
0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49,
|
0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49,
|
||||||
0x64, 0x12, 0x28, 0x0a, 0x08, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20,
|
0x64, 0x12, 0x28, 0x0a, 0x08, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20,
|
||||||
0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x44, 0x42, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74,
|
0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x44, 0x42, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74,
|
||||||
0x61, 0x52, 0x08, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x22, 0xb1, 0x01, 0x0a, 0x0b,
|
0x61, 0x52, 0x08, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x22, 0xaf, 0x02, 0x0a, 0x0b,
|
||||||
0x44, 0x42, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x12, 0x16, 0x0a, 0x06, 0x55,
|
0x44, 0x42, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x12, 0x0e, 0x0a, 0x02, 0x69,
|
||||||
0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x55, 0x73, 0x65,
|
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75,
|
||||||
0x72, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02,
|
0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x12, 0x0a,
|
||||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x1a, 0x0a,
|
0x04, 0x75, 0x75, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x75, 0x69,
|
||||||
0x08, 0x4e, 0x69, 0x63, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52,
|
0x64, 0x12, 0x18, 0x0a, 0x07, 0x62, 0x69, 0x6e, 0x64, 0x75, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01,
|
||||||
0x08, 0x4e, 0x69, 0x63, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x53, 0x65, 0x72,
|
0x28, 0x09, 0x52, 0x07, 0x62, 0x69, 0x6e, 0x64, 0x75, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e,
|
||||||
0x76, 0x65, 0x72, 0x49, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x53, 0x65, 0x72,
|
0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12,
|
||||||
0x76, 0x65, 0x72, 0x49, 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x50,
|
0x10, 0x0a, 0x03, 0x73, 0x69, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x73, 0x69,
|
||||||
0x6f, 0x69, 0x6e, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0b, 0x46, 0x72, 0x69, 0x65,
|
0x64, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x69, 0x70, 0x18, 0x07, 0x20,
|
||||||
0x6e, 0x64, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61,
|
0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x69, 0x70, 0x12, 0x20, 0x0a,
|
||||||
0x72, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x42,
|
0x0b, 0x6c, 0x61, 0x73, 0x74, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x69, 0x70, 0x18, 0x08, 0x20, 0x01,
|
||||||
0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
0x28, 0x09, 0x52, 0x0b, 0x6c, 0x61, 0x73, 0x74, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x69, 0x70, 0x12,
|
||||||
|
0x14, 0x0a, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05,
|
||||||
|
0x63, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x74, 0x69,
|
||||||
|
0x6d, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x74,
|
||||||
|
0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x50, 0x6f, 0x69,
|
||||||
|
0x6e, 0x74, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0b, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64,
|
||||||
|
0x50, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x18,
|
||||||
|
0x0c, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x42, 0x06, 0x5a,
|
||||||
|
0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -2,6 +2,7 @@ package services
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -12,7 +13,8 @@ import (
|
|||||||
"go_dreamfactory/lego/core/cbase"
|
"go_dreamfactory/lego/core/cbase"
|
||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
|
|
||||||
"google.golang.org/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
|
"github.com/golang/protobuf/ptypes"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -36,6 +38,7 @@ type SComp_GateRouteComp struct {
|
|||||||
cbase.ServiceCompBase
|
cbase.ServiceCompBase
|
||||||
service base.IRPCXService //rpc服务对象 通过这个对象可以发布服务和调用其他服务的接口
|
service base.IRPCXService //rpc服务对象 通过这个对象可以发布服务和调用其他服务的接口
|
||||||
mrlock sync.RWMutex //msghandles 对象的锁
|
mrlock sync.RWMutex //msghandles 对象的锁
|
||||||
|
msgcheck map[string]*msghandle //处理函数的校验接口
|
||||||
msghandles map[string]*msghandle //处理函数的管理对象
|
msghandles map[string]*msghandle //处理函数的管理对象
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,6 +59,15 @@ func (this *SComp_GateRouteComp) Init(service core.IService, comp core.IServiceC
|
|||||||
func (this *SComp_GateRouteComp) Start() (err error) {
|
func (this *SComp_GateRouteComp) Start() (err error) {
|
||||||
this.service.RegisterFunctionName(string(comm.Rpc_GatewayRoute), this.ReceiveMsg) //注册网关路由接收接口
|
this.service.RegisterFunctionName(string(comm.Rpc_GatewayRoute), this.ReceiveMsg) //注册网关路由接收接口
|
||||||
err = this.ServiceCompBase.Start()
|
err = this.ServiceCompBase.Start()
|
||||||
|
for k, v := range this.msghandles {
|
||||||
|
if v1, ok := this.msgcheck[k]; !ok {
|
||||||
|
err = fmt.Errorf("注册用户消息处理函数:%s 没有实现参数校验接口", k)
|
||||||
|
return
|
||||||
|
} else if v.msgType != v1.msgType {
|
||||||
|
err = fmt.Errorf("注册用户消息处理函数:%s 实现参数校验接口不一致 请检查代码!", k)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,19 +90,40 @@ func (this *SComp_GateRouteComp) RegisterRoute(methodName string, comp reflect.V
|
|||||||
this.mrlock.Unlock()
|
this.mrlock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//业务模块注册用户消息处理路由
|
||||||
|
func (this *SComp_GateRouteComp) RegisterRouteCheck(methodName string, comp reflect.Value, msg reflect.Type, fn reflect.Method) {
|
||||||
|
log.Debugf("注册用户路由校验[%s]", methodName)
|
||||||
|
this.mrlock.RLock()
|
||||||
|
_, ok := this.msgcheck[methodName]
|
||||||
|
this.mrlock.RUnlock()
|
||||||
|
if ok {
|
||||||
|
log.Errorf("重复 注册用户路由校验[%s]", methodName)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.mrlock.Lock()
|
||||||
|
this.msgcheck[methodName] = &msghandle{
|
||||||
|
rcvr: comp,
|
||||||
|
msgType: msg,
|
||||||
|
fn: fn,
|
||||||
|
}
|
||||||
|
this.mrlock.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
//Rpc_GatewayRoute服务接口的接收函数
|
//Rpc_GatewayRoute服务接口的接收函数
|
||||||
func (this *SComp_GateRouteComp) ReceiveMsg(ctx context.Context, args *pb.AgentMessage, reply *pb.RPCMessageReply) error {
|
func (this *SComp_GateRouteComp) ReceiveMsg(ctx context.Context, args *pb.AgentMessage, reply *pb.RPCMessageReply) error {
|
||||||
log.Debugf("SComp_GateRouteComp ReceiveMsg agent:%s uId:%s MessageDistribution msg:%s", args.UserSessionId, args.UserId, args.Method)
|
log.Debugf("SComp_GateRouteComp ReceiveMsg agent:%s uId:%s MessageDistribution msg:%s", args.UserSessionId, args.UserId, args.Method)
|
||||||
this.mrlock.RLock()
|
this.mrlock.RLock()
|
||||||
msghandle, ok := this.msghandles[args.Method]
|
msghandle, ok := this.msghandles[args.Method]
|
||||||
|
msgcheck := this.msghandles[args.Method]
|
||||||
this.mrlock.RUnlock()
|
this.mrlock.RUnlock()
|
||||||
if ok {
|
if ok {
|
||||||
session := comm.NewUserSession(this.service, args.Ip, args.UserSessionId, args.GatewayServiceId, args.UserId)
|
session := comm.NewUserSession(this.service, args.Ip, args.UserSessionId, args.GatewayServiceId, args.UserId)
|
||||||
msg := reflect.New(msghandle.msgType.Elem()).Interface()
|
msg := reflect.New(msghandle.msgType.Elem()).Interface()
|
||||||
if err := proto.Unmarshal(args.Message, msg.(proto.Message)); err != nil {
|
if err := ptypes.UnmarshalAny(args.Message, msg.(proto.Message)); err != nil {
|
||||||
log.Errorf("UserMessage:%s Unmarshal err:%v", args.Method, err)
|
log.Errorf("UserMessage:%s Unmarshal err:%v", args.Method, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
msghandle.fn.Func.Call([]reflect.Value{msgcheck.rcvr, reflect.ValueOf(ctx), reflect.ValueOf(session), reflect.ValueOf(msg)})
|
||||||
msghandle.fn.Func.Call([]reflect.Value{msghandle.rcvr, reflect.ValueOf(ctx), reflect.ValueOf(session), reflect.ValueOf(msg)})
|
msghandle.fn.Func.Call([]reflect.Value{msghandle.rcvr, reflect.ValueOf(ctx), reflect.ValueOf(session), reflect.ValueOf(msg)})
|
||||||
} else {
|
} else {
|
||||||
reply.Code = pb.ErrorCode_ReqParameterError
|
reply.Code = pb.ErrorCode_ReqParameterError
|
||||||
|
11
sys/cache/friend.go
vendored
11
sys/cache/friend.go
vendored
@ -17,14 +17,15 @@ func getRdsFriendKey(userId string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type IFriend interface {
|
type IFriend interface {
|
||||||
Friend_Apply(data *pb.Cache_FriendData) (err error)
|
Friend_Update(data *pb.Cache_FriendData) (err error)
|
||||||
Friend_Total(userId string) int32
|
Friend_Total(userId string) int32
|
||||||
Friend_Get(userId string) (*pb.Cache_FriendData, error)
|
Friend_Get(userId string) (*pb.Cache_FriendData, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
//好友申请
|
//更新
|
||||||
func (this *Cache) Friend_Apply(data *pb.Cache_FriendData) (err error) {
|
func (this *Cache) Friend_Update(data *pb.Cache_FriendData) (err error) {
|
||||||
if err = db.Defsys.Friend_Apply(data); err == nil {
|
if err = db.Defsys.Friend_SaveOrUpdate(data); err == nil {
|
||||||
|
//更新缓存
|
||||||
err = this.redis.Set(getRdsFriendKey(data.UserId), data, 0)
|
err = this.redis.Set(getRdsFriendKey(data.UserId), data, 0)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -47,7 +48,7 @@ func (this *Cache) Friend_Get(userId string) (*pb.Cache_FriendData, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if err.Error() == string(redis.RedisNil) {
|
if err.Error() == string(redis.RedisNil) {
|
||||||
d = &pb.Cache_FriendData{UserId: userId}
|
d = &pb.Cache_FriendData{UserId: userId}
|
||||||
err = this.Friend_Apply(d)
|
err = this.Friend_Update(d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return d, nil
|
return d, nil
|
||||||
}
|
}
|
||||||
|
2
sys/cache/friend_test.go
vendored
2
sys/cache/friend_test.go
vendored
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestFriendApply(t *testing.T) {
|
func TestFriendApply(t *testing.T) {
|
||||||
err := cache.Defsys.Friend_Apply(&pb.Cache_FriendData{
|
err := cache.Defsys.Friend_Update(&pb.Cache_FriendData{
|
||||||
UserId: "629f159310d6970846f7ef26",
|
UserId: "629f159310d6970846f7ef26",
|
||||||
FriendIds: []string{"629f147e3d276120561bfa18"},
|
FriendIds: []string{"629f147e3d276120561bfa18"},
|
||||||
ApplyIds: []string{"629eb3f4132dc4bb26139659"},
|
ApplyIds: []string{"629eb3f4132dc4bb26139659"},
|
||||||
|
43
sys/cache/pack.go
vendored
43
sys/cache/pack.go
vendored
@ -17,6 +17,7 @@ const ( //Redis
|
|||||||
const (
|
const (
|
||||||
GridCapMaxNum = 99 //单个格子的最大容量
|
GridCapMaxNum = 99 //单个格子的最大容量
|
||||||
GridMaxNUm = 200 //背包格子数量上限
|
GridMaxNUm = 200 //背包格子数量上限
|
||||||
|
Pack_Expiration = -1 //背包缓存数据过期时间
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -29,12 +30,16 @@ var (
|
|||||||
type IPack interface {
|
type IPack interface {
|
||||||
///查询用户背包
|
///查询用户背包
|
||||||
Pack_QueryUserPack(uId string) (pack *pb.DB_UserPackData, err error)
|
Pack_QueryUserPack(uId string) (pack *pb.DB_UserPackData, err error)
|
||||||
|
//查询用户背包物品数量
|
||||||
|
Pack_QueryUserPackItemAmount(uId string, itemid int32) (amount uint32)
|
||||||
///添加物品到背包 (可以加物品和减物品)
|
///添加物品到背包 (可以加物品和减物品)
|
||||||
Pack_AddItemToUserPack(uId string, itemId int32, addnum int32) (err error)
|
Pack_AddItemToUserPack(uId string, itemId int32, addnum int32) (err error)
|
||||||
///添加多个物品到背包 (可以加物品和减物品)
|
///添加多个物品到背包 (可以加物品和减物品)
|
||||||
Pack_AddItemsToUserPack(uId string, items map[int32]int32) (err error)
|
Pack_AddItemsToUserPack(uId string, items map[int32]int32) (err error)
|
||||||
//修改用户背包格子的标识
|
//修改用户背包格子的标识
|
||||||
Pack_ModifyPackGridIsNewItem(uId string, grids []int32) (err error)
|
Pack_ModifyPackGridIsNewItem(uId string, grids []int32) (err error)
|
||||||
|
//更新用户背包格子信息
|
||||||
|
Pack_UpdateGridToUserPack(uId string, grids ...*pb.DB_GridData) (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
///查询用户背包数据
|
///查询用户背包数据
|
||||||
@ -46,7 +51,7 @@ func (this *Cache) Pack_QueryUserPack(uId string) (pack *pb.DB_UserPackData, err
|
|||||||
return
|
return
|
||||||
} else if err == redis.RedisNil {
|
} else if err == redis.RedisNil {
|
||||||
if pack, err = db.Defsys.Pack_QueryUserPack(uId); err == nil {
|
if pack, err = db.Defsys.Pack_QueryUserPack(uId); err == nil {
|
||||||
this.redis.Set(fmt.Sprintf(Redis_PackCache, uId), pack, -1)
|
this.redis.Set(fmt.Sprintf(Redis_PackCache, uId), pack, Pack_Expiration)
|
||||||
} else if err == mgo.MongodbNil {
|
} else if err == mgo.MongodbNil {
|
||||||
err = nil
|
err = nil
|
||||||
}
|
}
|
||||||
@ -54,6 +59,23 @@ func (this *Cache) Pack_QueryUserPack(uId string) (pack *pb.DB_UserPackData, err
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//查询用户背包物品数量
|
||||||
|
func (this *Cache) Pack_QueryUserPackItemAmount(uId string, itemid int32) (amount uint32) {
|
||||||
|
var (
|
||||||
|
pack *pb.DB_UserPackData
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
if pack, err = this.Pack_QueryUserPack(uId); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, v := range pack.Pack {
|
||||||
|
if !v.IsEmpty && v.ItemId == itemid {
|
||||||
|
amount += v.Amount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
///添加或则减少物品到用户背包
|
///添加或则减少物品到用户背包
|
||||||
func (this *Cache) Pack_AddItemToUserPack(uId string, itemId int32, addnum int32) (err error) {
|
func (this *Cache) Pack_AddItemToUserPack(uId string, itemId int32, addnum int32) (err error) {
|
||||||
var (
|
var (
|
||||||
@ -76,7 +98,7 @@ func (this *Cache) Pack_AddItemToUserPack(uId string, itemId int32, addnum int32
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if pack, err = db.Defsys.Pack_UpdateGridToUserPack(uId, modifys...); err == nil {
|
if pack, err = db.Defsys.Pack_UpdateGridToUserPack(uId, modifys...); err == nil {
|
||||||
this.redis.Set(fmt.Sprintf(Redis_PackCache, uId), pack, -1)
|
this.redis.Set(fmt.Sprintf(Redis_PackCache, uId), pack, Pack_Expiration)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -116,7 +138,7 @@ func (this *Cache) Pack_AddItemsToUserPack(uId string, items map[int32]int32) (e
|
|||||||
}
|
}
|
||||||
|
|
||||||
if pack, err = db.Defsys.Pack_UpdateGridToUserPack(uId, modifys...); err == nil {
|
if pack, err = db.Defsys.Pack_UpdateGridToUserPack(uId, modifys...); err == nil {
|
||||||
this.redis.Set(fmt.Sprintf(Redis_PackCache, uId), pack, -1)
|
this.redis.Set(fmt.Sprintf(Redis_PackCache, uId), pack, Pack_Expiration)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -159,7 +181,7 @@ func (this *Cache) Pack_AddItemToUserPackByGrid(uId string, gridid int32, itemId
|
|||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
if pack, err = db.Defsys.Pack_UpdateGridToUserPack(uId, grid); err == nil {
|
if pack, err = db.Defsys.Pack_UpdateGridToUserPack(uId, grid); err == nil {
|
||||||
this.redis.Set(fmt.Sprintf(Redis_PackCache, uId), pack, -1)
|
this.redis.Set(fmt.Sprintf(Redis_PackCache, uId), pack, Pack_Expiration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,7 +194,18 @@ func (this *Cache) Pack_ModifyPackGridIsNewItem(uId string, grids []int32) (err
|
|||||||
pack *pb.DB_UserPackData
|
pack *pb.DB_UserPackData
|
||||||
)
|
)
|
||||||
if pack, err = db.Defsys.Pack_ModifyPackGridIsNewItem(uId, grids); err == nil {
|
if pack, err = db.Defsys.Pack_ModifyPackGridIsNewItem(uId, grids); err == nil {
|
||||||
err = this.redis.Set(fmt.Sprintf(Redis_PackCache, uId), pack, -1)
|
err = this.redis.Set(fmt.Sprintf(Redis_PackCache, uId), pack, Pack_Expiration)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
///修改目标格子的新获取标识
|
||||||
|
func (this *Cache) Pack_UpdateGridToUserPack(uId string, grids ...*pb.DB_GridData) (err error) {
|
||||||
|
var (
|
||||||
|
pack *pb.DB_UserPackData
|
||||||
|
)
|
||||||
|
if pack, err = db.Defsys.Pack_UpdateGridToUserPack(uId, grids...); err == nil {
|
||||||
|
err = this.redis.Set(fmt.Sprintf(Redis_PackCache, uId), pack, Pack_Expiration)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
6
sys/cache/user.go
vendored
6
sys/cache/user.go
vendored
@ -3,6 +3,7 @@ package cache
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
|
"go_dreamfactory/sys/db"
|
||||||
|
|
||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
)
|
)
|
||||||
@ -17,7 +18,10 @@ type IUser interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *Cache) Update(data *pb.Cache_UserData) (err error) {
|
func (this *Cache) Update(data *pb.Cache_UserData) (err error) {
|
||||||
err = this.redis.Set(fmt.Sprintf(Redis_UserCache, data.UserData.UserId), data, -1)
|
err = db.Defsys.User_Update(data.UserData)
|
||||||
|
if err == nil {
|
||||||
|
err = this.redis.Set(fmt.Sprintf(Redis_UserCache, data.UserData.Uid), data, -1)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
sys/cache/user_test.go
vendored
4
sys/cache/user_test.go
vendored
@ -15,8 +15,8 @@ func TestUpdateUser(t *testing.T) {
|
|||||||
SessionId: "1",
|
SessionId: "1",
|
||||||
GatewayServiceId: "work",
|
GatewayServiceId: "work",
|
||||||
UserData: &pb.DB_UserData{
|
UserData: &pb.DB_UserData{
|
||||||
UserId: primitive.NewObjectID().Hex(),
|
Uid: primitive.NewObjectID().Hex(),
|
||||||
Account: "aaa",
|
Name: "aaa",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
err := cache.Defsys.Update(user)
|
err := cache.Defsys.Update(user)
|
||||||
|
@ -2,6 +2,7 @@ package db
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"go_dreamfactory/lego/core"
|
"go_dreamfactory/lego/core"
|
||||||
|
"go_dreamfactory/lego/sys/log"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
@ -14,11 +15,12 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type IFriend interface {
|
type IFriend interface {
|
||||||
Friend_Apply(data *pb.Cache_FriendData) (err error)
|
Friend_SaveOrUpdate(data *pb.Cache_FriendData) (err error)
|
||||||
|
Frined_FindCond(nickName string) *pb.DB_UserData
|
||||||
}
|
}
|
||||||
|
|
||||||
//好友申请
|
//好友
|
||||||
func (this *DB) Friend_Apply(data *pb.Cache_FriendData) (err error) {
|
func (this *DB) Friend_SaveOrUpdate(data *pb.Cache_FriendData) (err error) {
|
||||||
err = this.mgo.FindOneAndUpdate(DB_FriendTable,
|
err = this.mgo.FindOneAndUpdate(DB_FriendTable,
|
||||||
bson.M{"_id": data.UserId},
|
bson.M{"_id": data.UserId},
|
||||||
bson.M{"$set": bson.M{
|
bson.M{"$set": bson.M{
|
||||||
@ -32,3 +34,15 @@ func (this *DB) Friend_Apply(data *pb.Cache_FriendData) (err error) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *DB) Frined_FindCond(nickName string) *pb.DB_UserData {
|
||||||
|
var user *pb.DB_UserData
|
||||||
|
err := this.mgo.FindOne(DB_UserTable, bson.M{
|
||||||
|
"nicename": nickName,
|
||||||
|
}).Decode(&user)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("findCond err:%v", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return user
|
||||||
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package db
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -8,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestFriendAdd(t *testing.T) {
|
func TestFriendAdd(t *testing.T) {
|
||||||
err := db.Friend_Apply(&pb.Cache_FriendData{
|
err := db.Friend_SaveOrUpdate(&pb.Cache_FriendData{
|
||||||
UserId: "629f159310d6970846f7ef26",
|
UserId: "629f159310d6970846f7ef26",
|
||||||
FriendIds: []string{
|
FriendIds: []string{
|
||||||
"629f147e3d276120561bfa18",
|
"629f147e3d276120561bfa18",
|
||||||
@ -17,3 +18,10 @@ func TestFriendAdd(t *testing.T) {
|
|||||||
|
|
||||||
require.Nil(t, err, nil)
|
require.Nil(t, err, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFriendFindCond(t *testing.T) {
|
||||||
|
user := db.Frined_FindCond("乐谷5")
|
||||||
|
require.NotNil(t, user, nil)
|
||||||
|
|
||||||
|
fmt.Printf("%v", user)
|
||||||
|
}
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package db
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
|
"time"
|
||||||
|
|
||||||
"go_dreamfactory/lego/core"
|
"go_dreamfactory/lego/core"
|
||||||
|
|
||||||
|
uuid "github.com/satori/go.uuid"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
@ -24,8 +27,8 @@ type IUser interface {
|
|||||||
//
|
//
|
||||||
func (this *DB) User_FindByAccount(user *pb.DB_UserData) (*pb.DB_UserData, error) {
|
func (this *DB) User_FindByAccount(user *pb.DB_UserData) (*pb.DB_UserData, error) {
|
||||||
filter := bson.M{
|
filter := bson.M{
|
||||||
"serverid": user.ServerId,
|
"sid": user.Sid,
|
||||||
"account": user.Account,
|
"binduid": user.Binduid,
|
||||||
}
|
}
|
||||||
sr := this.mgo.FindOne(DB_UserTable, filter)
|
sr := this.mgo.FindOne(DB_UserTable, filter)
|
||||||
var nd *pb.DB_UserData
|
var nd *pb.DB_UserData
|
||||||
@ -35,7 +38,7 @@ func (this *DB) User_FindByAccount(user *pb.DB_UserData) (*pb.DB_UserData, error
|
|||||||
|
|
||||||
func (this *DB) User_FindById(id string) (*pb.DB_UserData, error) {
|
func (this *DB) User_FindById(id string) (*pb.DB_UserData, error) {
|
||||||
filter := bson.M{
|
filter := bson.M{
|
||||||
"_id": id,
|
"userid": id,
|
||||||
}
|
}
|
||||||
sr := this.mgo.FindOne(DB_UserTable, filter)
|
sr := this.mgo.FindOne(DB_UserTable, filter)
|
||||||
user := &pb.DB_UserData{}
|
user := &pb.DB_UserData{}
|
||||||
@ -44,7 +47,11 @@ func (this *DB) User_FindById(id string) (*pb.DB_UserData, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *DB) User_Create(user *pb.DB_UserData) (err error) {
|
func (this *DB) User_Create(user *pb.DB_UserData) (err error) {
|
||||||
user.UserId = primitive.NewObjectID().Hex()
|
_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)
|
_, err = this.mgo.InsertOne(DB_UserTable, user)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -53,11 +60,11 @@ func (this *DB) User_Create(user *pb.DB_UserData) (err error) {
|
|||||||
func (this *DB) User_Update(data *pb.DB_UserData) (err error) {
|
func (this *DB) User_Update(data *pb.DB_UserData) (err error) {
|
||||||
err = this.mgo.FindOneAndUpdate(
|
err = this.mgo.FindOneAndUpdate(
|
||||||
DB_UserTable,
|
DB_UserTable,
|
||||||
bson.M{"_id": data.UserId},
|
bson.M{"uid": data.Uid},
|
||||||
bson.M{"$set": bson.M{
|
bson.M{"$set": bson.M{
|
||||||
"niceName": data.NiceName,
|
"name": data.Name,
|
||||||
}},
|
}},
|
||||||
options.FindOneAndUpdate().SetUpsert(false).SetReturnDocument(options.After),
|
options.FindOneAndUpdate().SetUpsert(true),
|
||||||
).Decode(data)
|
).Err()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,9 @@ import (
|
|||||||
|
|
||||||
func TestCreate(t *testing.T) {
|
func TestCreate(t *testing.T) {
|
||||||
user := &pb.DB_UserData{
|
user := &pb.DB_UserData{
|
||||||
Account: "legu3",
|
Binduid: "legu131",
|
||||||
NiceName: "乐谷3",
|
Name: "legu131",
|
||||||
ServerId: 1,
|
Sid: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := db.User_Create(user)
|
err := db.User_Create(user)
|
||||||
@ -23,18 +23,18 @@ func TestCreate(t *testing.T) {
|
|||||||
func TestFindOne(t *testing.T) {
|
func TestFindOne(t *testing.T) {
|
||||||
user, err := db.User_FindById("629eb3f4132dc4bb26139659")
|
user, err := db.User_FindById("629eb3f4132dc4bb26139659")
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
assert.Equal(t, "legu3", user.Account)
|
assert.Equal(t, "legu3", user.Binduid)
|
||||||
|
|
||||||
// user.ServerId = 2
|
// user.ServerId = 2
|
||||||
user2, err := db.User_FindByAccount(user)
|
user2, err := db.User_FindByAccount(user)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
assert.Equal(t, "legu3", user2.Account)
|
assert.Equal(t, "legu3", user2.Binduid)
|
||||||
assert.Equal(t, int32(1), user2.ServerId)
|
assert.Equal(t, int32(1), user2.Sid)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdate(t *testing.T) {
|
func TestUpdate(t *testing.T) {
|
||||||
user := &pb.DB_UserData{
|
user := &pb.DB_UserData{
|
||||||
UserId: primitive.NewObjectID().Hex(),
|
Uuid: primitive.NewObjectID().Hex(),
|
||||||
}
|
}
|
||||||
err := db.User_Update(user)
|
err := db.User_Update(user)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
@ -16,7 +16,6 @@ func ParseP(p string) (string, string, bool) {
|
|||||||
return s[0], s[1], true
|
return s[0], s[1], true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func Find(slice []string, val string) (int, bool) {
|
func Find(slice []string, val string) (int, bool) {
|
||||||
for i, item := range slice {
|
for i, item := range slice {
|
||||||
if item == val {
|
if item == val {
|
||||||
@ -25,3 +24,13 @@ func Find(slice []string, val string) (int, bool) {
|
|||||||
}
|
}
|
||||||
return -1, false
|
return -1, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DeleteString(list []string, ele string) []string {
|
||||||
|
result := make([]string, 0)
|
||||||
|
for _, v := range list {
|
||||||
|
if v != ele {
|
||||||
|
result = append(result, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user