mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-26 11:28:46 +08:00
462ddbb145
* Add grpc retry * Update grpc retry * Add tests * Fix a bug * Add api && some tests * Add comment * Add double check * Add server retry quota * Update optimize code * Fix bug * Update optimize code * Update optimize code * Fix bug
20 lines
616 B
Go
20 lines
616 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 {
|
|
return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
|
|
if !enable {
|
|
return invoker(ctx, method, req, reply, cc, opts...)
|
|
}
|
|
return retry.Do(ctx, func(ctx context.Context, callOpts ...grpc.CallOption) error {
|
|
return invoker(ctx, method, req, reply, cc, callOpts...)
|
|
}, opts...)
|
|
}
|
|
}
|