diff --git a/cmd/rpc/open_im_msg/main.go b/cmd/rpc/open_im_msg/main.go index 2c6d785d7..6c689033a 100644 --- a/cmd/rpc/open_im_msg/main.go +++ b/cmd/rpc/open_im_msg/main.go @@ -12,7 +12,7 @@ func main() { rpcServer := rpcChat.NewRpcChatServer(*rpcPort) // register widgets - // mock + // mock 注册发送前的拦截器 rpcServer.UseWidgetBeforSend(widget.MockBeforeSendHandler) // diff --git a/cmd/rpc/open_im_msg/widget/widget.go b/cmd/rpc/open_im_msg/widget/widget.go index 9f9224a64..92d3c5e50 100644 --- a/cmd/rpc/open_im_msg/widget/widget.go +++ b/cmd/rpc/open_im_msg/widget/widget.go @@ -5,13 +5,17 @@ import ( pbChat "Open_IM/pkg/proto/chat" "context" "errors" + "fmt" ) // MockBeforeSendHandler is a mock handle that handles custom logic before send msg. func MockBeforeSendHandler(ctx context.Context, pb *pbChat.SendMsgReq) (*pbChat.SendMsgResp, bool, error) { + fmt.Printf("MockBeforeSendHandler trigger,contentType:%d\n", pb.MsgData.GetContentType()) if pb.MsgData.ContentType == constant.Text { msg := string(pb.MsgData.Content) + fmt.Printf("text msg:%s", msg) if msg == "this is a m..m..mock msg" { + fmt.Println(".==>msg had banned") return nil, false, errors.New("BANG! This msg has been banned by MockBeforeSendHandler") } }