2015-09-19 13:02:59 +02:00
|
|
|
package middlewares
|
2015-09-24 14:32:37 +02:00
|
|
|
|
2015-09-19 13:02:59 +02:00
|
|
|
import (
|
2015-09-24 14:32:37 +02:00
|
|
|
"net/http"
|
2015-09-24 17:16:13 +02:00
|
|
|
|
2016-03-15 23:27:07 +01:00
|
|
|
"github.com/containous/oxy/cbreaker"
|
2015-09-19 13:02:59 +02:00
|
|
|
)
|
|
|
|
|
2015-11-01 19:34:54 +01:00
|
|
|
// CircuitBreaker holds the oxy circuit breaker.
|
2015-09-19 13:02:59 +02:00
|
|
|
type CircuitBreaker struct {
|
|
|
|
circuitBreaker *cbreaker.CircuitBreaker
|
|
|
|
}
|
|
|
|
|
2015-11-01 19:34:54 +01:00
|
|
|
// NewCircuitBreaker returns a new CircuitBreaker.
|
2015-09-25 11:44:19 +02:00
|
|
|
func NewCircuitBreaker(next http.Handler, expression string, options ...cbreaker.CircuitBreakerOption) *CircuitBreaker {
|
|
|
|
circuitBreaker, _ := cbreaker.New(next, expression, options...)
|
2015-09-19 13:02:59 +02:00
|
|
|
return &CircuitBreaker{circuitBreaker}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cb *CircuitBreaker) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
|
|
|
cb.circuitBreaker.ServeHTTP(rw, r)
|
|
|
|
}
|