WithGroupcontainer/groupOperationWithGroupBreaker
// WithGroup with circuit breaker group.
// NOTE: implements generics circuitbreaker.CircuitBreaker
func WithGroup(g *group.Group) Option {
 return func(o *options) {
        o.group = g
 }
}
Operation
opt := &options{
    group: group.NewGroup(func() interface{} {
 return sre.NewBreaker()
 }),
}

懒加载容器aegis/circuitbreaker
// CircuitBreaker is a circuit breaker.
type CircuitBreaker interface {
 Allow() error // 判断请求是否允许发送,如果返回 error 则表示请求被拒绝
 MarkSuccess() // 标记请求成功
 MarkFailed() // 标记请求失败
}



使用方法​
在 Client 请求中使用熔断器​

// http
conn, err := http.NewClient(
    context.Background(),
    http.WithMiddleware(
        circuitbreaker.Client(),
 ),
    http.WithEndpoint("127.0.0.1:8000"),
)
// grpc 
conn,err := transgrpc.Dial(
  context.Background(), 
    grpc.WithMiddleware(
        circuitbreaker.Client(),
 ),
  grpc.WithEndpoint("127.0.0.1:9000"),
)

OperationErrNotAllowed
// ErrNotAllowed is request failed due to circuit breaker triggered.
var ErrNotAllowed = errors.New(503, "CIRCUITBREAKER", "request failed due to circuit breaker triggered")