上传接口格式优化
This commit is contained in:
parent
73a8d59ebe
commit
09ecaa3207
@ -54,6 +54,7 @@ type IUserSession interface {
|
||||
Bind(uid string, wokerId string) (err error)
|
||||
UnBind() (err error)
|
||||
SendMsg(mainType, subType string, msg proto.Message) (err error)
|
||||
Polls() []*pb.UserMessage
|
||||
Close() (err error)
|
||||
ToString() string
|
||||
}
|
||||
|
@ -89,17 +89,24 @@ func (this *UserSession) UnBind() (err error) {
|
||||
|
||||
//向用户发送消息
|
||||
func (this *UserSession) SendMsg(mainType, subType string, msg proto.Message) (err error) {
|
||||
reply := &pb.RPCMessageReply{}
|
||||
data, _ := anypb.New(msg)
|
||||
log.Debugf("SendMsg to SessionId:[%s] UserId:[%s] Data: %v", this.UserId, msg)
|
||||
if err := this.service.RpcCall(context.Background(), fmt.Sprintf("%s/%s", Service_Gateway, this.GatewayServiceId), string(Rpc_GatewayAgentSendMsg), &pb.AgentSendMessageReq{
|
||||
UserSessionId: this.SessionId,
|
||||
MainType: mainType,
|
||||
SubType: subType,
|
||||
Data: data,
|
||||
}, reply); err != nil {
|
||||
log.Errorf("SendMsg:%s UserSession:%s UserId:%s err:%v", mainType, this.SessionId, this.UserId, err)
|
||||
}
|
||||
data, _ := anypb.New(msg)
|
||||
this.msgqueue = append(this.msgqueue, &pb.UserMessage{
|
||||
MainType: mainType,
|
||||
SubType: subType,
|
||||
Data: data,
|
||||
})
|
||||
// reply := &pb.RPCMessageReply{}
|
||||
// data, _ := anypb.New(msg)
|
||||
// log.Debugf("SendMsg to SessionId:[%s] UserId:[%s] Data: %v", this.UserId, msg)
|
||||
// if err := this.service.RpcCall(context.Background(), fmt.Sprintf("%s/%s", Service_Gateway, this.GatewayServiceId), string(Rpc_GatewayAgentSendMsg), &pb.AgentSendMessageReq{
|
||||
// UserSessionId: this.SessionId,
|
||||
// MainType: mainType,
|
||||
// SubType: subType,
|
||||
// Data: data,
|
||||
// }, reply); err != nil {
|
||||
// log.Errorf("SendMsg:%s UserSession:%s UserId:%s err:%v", mainType, this.SessionId, this.UserId, err)
|
||||
// }
|
||||
return
|
||||
}
|
||||
|
||||
@ -114,6 +121,13 @@ func (this *UserSession) Close() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
//清空消息队列
|
||||
func (this *UserSession) Polls() []*pb.UserMessage {
|
||||
msgs := this.msgqueue
|
||||
this.msgqueue = this.msgqueue[:0]
|
||||
return msgs
|
||||
}
|
||||
|
||||
//打印日志需要
|
||||
func (this *UserSession) ToString() string {
|
||||
return fmt.Sprintf("SessionId:%s UserId:%s GatewayServiceId:%s", this.SessionId, this.UserId, this.GatewayServiceId)
|
||||
|
@ -18,12 +18,12 @@ const (
|
||||
)
|
||||
|
||||
type apiComp struct {
|
||||
modules.MComp_GateComp
|
||||
modules.MCompGate
|
||||
module *Friend
|
||||
}
|
||||
|
||||
func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||
this.MComp_GateComp.Init(service, module, comp, options)
|
||||
this.MCompGate.Init(service, module, comp, options)
|
||||
this.module = module.(*Friend)
|
||||
return
|
||||
}
|
||||
|
@ -143,8 +143,9 @@ func (this *SCompGateRoute) ReceiveMsg(ctx context.Context, args *pb.AgentMessag
|
||||
reply.Code = errcode
|
||||
reply.ErrorMessage = pb.GetErrorCodeMsg(errcode)
|
||||
return nil
|
||||
} else {
|
||||
reply.Reply = session.Polls()
|
||||
}
|
||||
|
||||
} else { //未找到消息处理函数
|
||||
reply.Code = pb.ErrorCode_ReqParameterError
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user