mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-25 02:08:44 +08:00
20 lines
489 B
Go
20 lines
489 B
Go
package clientinterceptors
|
|
|
|
import (
|
|
"context"
|
|
"path"
|
|
|
|
"zero/core/breaker"
|
|
"zero/rpcx/internal/codes"
|
|
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
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...)
|
|
}, codes.Acceptable)
|
|
}
|