package modules import ( "context" "go_dreamfactory/comm" "go_dreamfactory/pb" "github.com/liwei1dao/lego/base" "github.com/liwei1dao/lego/core" "github.com/liwei1dao/lego/core/cbase" "github.com/liwei1dao/lego/sys/log" "google.golang.org/protobuf/proto" ) type ModuleBase struct { cbase.ModuleBase service base.IRPCXService } func (this *ModuleBase) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { err = this.ModuleBase.Init(service, module, options) this.service = service.(base.IRPCXService) return } func (this *ModuleBase) SendMsgToAgent(GatewayServiceId, SessionId, ServiceMethod string, msg proto.Message) (err error) { reply := &pb.RPCMessageReply{} data, _ := proto.Marshal(msg) if err = this.service.RpcCallById(GatewayServiceId, string(comm.Rpc_GatewayAgentSendMsg), context.Background(), &pb.AgentSendMessageReq{ UserSessionId: SessionId, ServiceMethod: ServiceMethod, Data: data, }, reply); err != nil { log.Errorf("SendMsgToAgent%s:[%s] err:%v", SessionId, ServiceMethod, err) } return } func (this *ModuleBase) SendMsgToAgents(GatewayServiceId, SessionId, ServiceMethod string, msg proto.Message) (err error) { reply := &pb.RPCMessageReply{} data, _ := proto.Marshal(msg) if err = this.service.RpcCallById(GatewayServiceId, string(comm.Rpc_GatewayAgentSendMsg), context.Background(), &pb.AgentSendMessageReq{ UserSessionId: SessionId, ServiceMethod: ServiceMethod, Data: data, }, reply); err != nil { log.Errorf("SendMsgToAgent%s:[%s] err:%v", SessionId, ServiceMethod, err) } return }