mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-25 02:08:44 +08:00
eda8230521
* chore: reverse the order of stopping services * chore: reverse the order of stopping services * chore: reorg imports, format code * chore: format code, and refactor * feat: change MaxRetries default to 0, disable retry
26 lines
780 B
Go
26 lines
780 B
Go
package clientinterceptors
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/tal-tech/go-zero/core/retry"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
// RetryInterceptor retry interceptor
|
|
func RetryInterceptor(enable bool) grpc.UnaryClientInterceptor {
|
|
if !enable {
|
|
return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn,
|
|
invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
|
|
return invoker(ctx, method, req, reply, cc, opts...)
|
|
}
|
|
}
|
|
|
|
return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn,
|
|
invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
|
|
return retry.Do(ctx, func(ctx context.Context, callOpts ...grpc.CallOption) error {
|
|
return invoker(ctx, method, req, reply, cc, callOpts...)
|
|
}, opts...)
|
|
}
|
|
}
|