Interceptor拦截器 -- gRPC生态里的中间件

Interceptor拦截器 -- gRPC生态里的中间件_kevin_tech的博客-CSDN博客 https://blog.csdn.net/kevin_tech/article/details/116141626

 

func OneInterceptor() grpc.UnaryServerInterceptor { return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) { defer func() { if err := recover(); err != nil { fmt.Println("fatal error:", err,string(debug.Stack())) } }() fmt.Println("before handler") // do real RPC res, err := handler(ctx, req) fmt.Println("after handler") return res, err } }

gRPC 之 Interceptor 实战篇 - 熊喵君的博客 | PANDAYCHEN https://pandaychen.github.io/2019/11/20/GRPC-INTERCEPTOR-APPLY/

 

posted @ 2021-05-17 23:04  papering  阅读(216)  评论(0编辑  收藏  举报