breakerinterceptor.go 534 B

123456789101112131415161718
  1. package clientinterceptors
  2. import (
  3. "context"
  4. "path"
  5. "github.com/tal-tech/go-zero/core/breaker"
  6. "github.com/tal-tech/go-zero/zrpc/internal/codes"
  7. "google.golang.org/grpc"
  8. )
  9. func BreakerInterceptor(ctx context.Context, method string, req, reply interface{},
  10. cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
  11. breakerName := path.Join(cc.Target(), method)
  12. return breaker.DoWithAcceptable(breakerName, func() error {
  13. return invoker(ctx, method, req, reply, cc, opts...)
  14. }, codes.Acceptable)
  15. }