add PreCall and PostCall plugins of server

This commit is contained in:
smallnest
2020-05-12 20:28:15 +08:00
parent 60ffe5d5ba
commit 691cb10a34
2 changed files with 50 additions and 0 deletions

View File

@@ -529,12 +529,22 @@ func (s *Server) handleRequest(ctx context.Context, req *protocol.Message) (res
replyv := argsReplyPools.Get(mtype.ReplyType)
argv, err = s.Plugins.DoPreCall(ctx, argv)
if err != nil {
argsReplyPools.Put(mtype.ReplyType, replyv)
return handleError(res, err)
}
if mtype.ArgType.Kind() != reflect.Ptr {
err = service.call(ctx, mtype, reflect.ValueOf(argv).Elem(), reflect.ValueOf(replyv))
} else {
err = service.call(ctx, mtype, reflect.ValueOf(argv), reflect.ValueOf(replyv))
}
if err == nil {
replyv, err = s.Plugins.DoPostCall(ctx, argv, replyv)
}
argsReplyPools.Put(mtype.ArgType, argv)
if err != nil {
argsReplyPools.Put(mtype.ReplyType, replyv)