fix after filter 没有返回最终的返回值问题

pull/145/head
ltf 4 years ago
parent 62b76f06c8
commit aebfe58034

@ -47,9 +47,10 @@ func MockBeforeSendFilter2(ctx *rpcChat.SendContext, pb *pbChat.SendMsgReq) (*pb
} }
fmt.Printf("MockBeforeSendFilter2 trigger,contentType:%d\n", pb.MsgData.GetContentType()) fmt.Printf("MockBeforeSendFilter2 trigger,contentType:%d\n", pb.MsgData.GetContentType())
msg := string(pb.MsgData.Content)
fmt.Printf("msg content:%s\n", msg)
if pb.MsgData.ContentType == constant.Text { if pb.MsgData.ContentType == constant.Text {
msg := string(pb.MsgData.Content) msg := string(pb.MsgData.Content)
// fmt.Printf("text msg:%s\n", msg)
if msg == "this is a m..m..mock msg" { if msg == "this is a m..m..mock msg" {
fmt.Println(".==>msg had banned") fmt.Println(".==>msg had banned")
return nil, false, errors.New("BANG! This msg has been banned by MockBeforeSendHandler") return nil, false, errors.New("BANG! This msg has been banned by MockBeforeSendHandler")

@ -45,17 +45,21 @@ func (c *SendContext) doBeforeFilters(pb *pbChat.SendMsgReq) (*pbChat.SendMsgRes
// doAfterFilters executes the pending filters in the chain inside the calling handler. // doAfterFilters executes the pending filters in the chain inside the calling handler.
func (c *SendContext) doAfterFilters(req *pbChat.SendMsgReq, res *pbChat.SendMsgResp) (*pbChat.SendMsgResp, bool, error) { func (c *SendContext) doAfterFilters(req *pbChat.SendMsgReq, res *pbChat.SendMsgResp) (*pbChat.SendMsgResp, bool, error) {
var (
ok bool
err error
)
for _, handler := range c.afterSenders { for _, handler := range c.afterSenders {
res, ok, err := handler(c, req, res) res, ok, err = handler(c, req, res)
if err != nil { if err != nil {
return nil, false, err return res, false, err
} }
if !ok { if !ok {
return res, ok, nil return res, ok, nil
} }
} }
return nil, true, nil return res, true, nil
} }
func (c *SendContext) SendMsg(pb *pbChat.SendMsgReq) (*pbChat.SendMsgResp, error) { func (c *SendContext) SendMsg(pb *pbChat.SendMsgReq) (*pbChat.SendMsgResp, error) {

Loading…
Cancel
Save