github.com/msales/pkg/v3@v3.24.0/grpcx/middleware/chain.go (about) 1 // This file contains simple convenience functions. 2 // It only chains library function calls, with no added logic. 3 4 package middleware 5 6 import ( 7 "github.com/grpc-ecosystem/go-grpc-middleware" 8 "google.golang.org/grpc" 9 ) 10 11 // WithUnaryClientInterceptors wraps multiple unary client interceptors in a single option. 12 func WithUnaryClientInterceptors(interceptors ...grpc.UnaryClientInterceptor) grpc.DialOption { 13 return grpc.WithUnaryInterceptor(grpc_middleware.ChainUnaryClient(interceptors...)) 14 } 15 16 // WithStreamClientInterceptors wraps multiple stream client interceptors in a single option. 17 func WithStreamClientInterceptors(interceptors ...grpc.StreamClientInterceptor) grpc.DialOption { 18 return grpc.WithStreamInterceptor(grpc_middleware.ChainStreamClient(interceptors...)) 19 } 20 21 // WithUnaryServerInterceptors wraps multiple unary server interceptors in a single option. 22 func WithUnaryServerInterceptors(interceptors ...grpc.UnaryServerInterceptor) grpc.ServerOption { 23 return grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(interceptors...)) 24 } 25 26 // WithStreamServerInterceptors wraps multiple stream server interceptors in a single option. 27 func WithStreamServerInterceptors(interceptors ...grpc.StreamServerInterceptor) grpc.ServerOption { 28 return grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(interceptors...)) 29 }