2015-09-19 11:02:59 +00:00
|
|
|
/*
|
|
|
|
Copyright
|
|
|
|
*/
|
|
|
|
package middlewares
|
2015-09-24 12:32:37 +00:00
|
|
|
|
2015-09-19 11:02:59 +00:00
|
|
|
import (
|
2015-09-24 12:32:37 +00:00
|
|
|
"net/http"
|
2015-09-24 15:16:13 +00:00
|
|
|
|
|
|
|
"github.com/mailgun/oxy/cbreaker"
|
2015-09-19 11:02:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type CircuitBreaker struct {
|
|
|
|
circuitBreaker *cbreaker.CircuitBreaker
|
|
|
|
}
|
|
|
|
|
2015-09-25 09:44:19 +00:00
|
|
|
func NewCircuitBreaker(next http.Handler, expression string, options ...cbreaker.CircuitBreakerOption) *CircuitBreaker {
|
|
|
|
circuitBreaker, _ := cbreaker.New(next, expression, options...)
|
2015-09-19 11:02:59 +00:00
|
|
|
return &CircuitBreaker{circuitBreaker}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cb *CircuitBreaker) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
|
|
|
cb.circuitBreaker.ServeHTTP(rw, r)
|
|
|
|
}
|