12345678910111213141516171819 |
- package clientinterceptors
- import (
- "context"
- "path"
- "git.i2edu.net/i2/go-zero/core/breaker"
- "git.i2edu.net/i2/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 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)
- }
|