package clientinterceptors import ( "context" "path" "zero/core/breaker" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) func acceptable(err error) bool { switch status.Code(err) { case codes.DeadlineExceeded, codes.Internal, codes.Unavailable, codes.DataLoss: return false default: return true } } func BreakerInterceptor(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { breakerName := path.Join(cc.Target(), method) return breaker.DoWithAcceptable(breakerName, func() error { return invoker(ctx, method, req, reply, cc, opts...) }, acceptable) }