mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-24 01:30:25 +08:00
ae87114282
* chore: change interface{} to any * chore: update goctl version to 1.5.0 * chore: update goctl deps
20 lines
600 B
Go
20 lines
600 B
Go
package clientinterceptors
|
|
|
|
import (
|
|
"context"
|
|
"path"
|
|
|
|
"github.com/zeromicro/go-zero/core/breaker"
|
|
"github.com/zeromicro/go-zero/zrpc/internal/codes"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
// BreakerInterceptor is an interceptor that acts as a circuit breaker.
|
|
func BreakerInterceptor(ctx context.Context, method string, req, reply any,
|
|
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)
|
|
}
|