| 1 | package circuitbreakerscip-go gomod github.com/go-kit/kit . `github.com/go-kit/kit/circuitbreaker`/ |
| 2 | |
| 3 | import ( |
| 4 | "contextscip-go gomod github.com/golang/go/src go1.17 context/" |
| 5 | "timescip-go gomod github.com/golang/go/src go1.17 time/" |
| 6 | |
| 7 | "github.com/streadway/handy/breakerscip-go gomod github.com/streadway/handy 0f66f006fb2e `github.com/streadway/handy/breaker`/" |
| 8 | |
| 9 | "github.com/go-kit/kit/endpointscip-go gomod github.com/go-kit/kit . `github.com/go-kit/kit/endpoint`/" |
| 10 | ) |
| 11 | |
| 12 | // HandyBreaker returns an endpoint.Middleware that implements the circuit |
| 13 | // breaker pattern using the streadway/handy/breaker package. Only errors |
| 14 | // returned by the wrapped endpoint count against the circuit breaker's error |
| 15 | // count. |
| 16 | // |
| 17 | // See http://godoc.org/github.com/streadway/handy/breaker for more |
| 18 | // information. |
| 19 | func HandyBreakerscip-go gomod github.com/go-kit/kit . `github.com/go-kit/kit/circuitbreaker`/HandyBreaker().(cb breakerscip-go gomod github.com/streadway/handy 0f66f006fb2e `github.com/streadway/handy/breaker`/.Breakerscip-go gomod github.com/streadway/handy 0f66f006fb2e `github.com/streadway/handy/breaker`/Breaker#) endpointscip-go gomod github.com/go-kit/kit . `github.com/go-kit/kit/endpoint`/.Middlewarescip-go gomod github.com/go-kit/kit . `github.com/go-kit/kit/endpoint`/Middleware# { |
| 20 | return func(next endpointscip-go gomod github.com/go-kit/kit . `github.com/go-kit/kit/endpoint`/.Endpointscip-go gomod github.com/go-kit/kit . `github.com/go-kit/kit/endpoint`/Endpoint#) endpointscip-go gomod github.com/go-kit/kit . `github.com/go-kit/kit/endpoint`/.Endpointscip-go gomod github.com/go-kit/kit . `github.com/go-kit/kit/endpoint`/Endpoint# { |
| 21 | return func(ctx contextscip-go gomod github.com/golang/go/src go1.17 context/.Contextscip-go gomod github.com/golang/go/src go1.17 context/Context#, request interface{}) (response interface{}, err error) { |
| 22 | if !cb.Allowscip-go gomod github.com/streadway/handy 0f66f006fb2e `github.com/streadway/handy/breaker`/Breaker#Allow().() { |
| 23 | return nil, breakerscip-go gomod github.com/streadway/handy 0f66f006fb2e `github.com/streadway/handy/breaker`/.ErrCircuitOpenscip-go gomod github.com/streadway/handy 0f66f006fb2e `github.com/streadway/handy/breaker`/ErrCircuitOpen. |
| 24 | } |
| 25 | |
| 26 | defer func(begin timescip-go gomod github.com/golang/go/src go1.17 time/.Timescip-go gomod github.com/golang/go/src go1.17 time/Time#) { |
| 27 | if err == nil { |
| 28 | cb.Successscip-go gomod github.com/streadway/handy 0f66f006fb2e `github.com/streadway/handy/breaker`/Breaker#Success().(timescip-go gomod github.com/golang/go/src go1.17 time/.Sincescip-go gomod github.com/golang/go/src go1.17 time/Since().(begin)) |
| 29 | } else { |
| 30 | cb.Failurescip-go gomod github.com/streadway/handy 0f66f006fb2e `github.com/streadway/handy/breaker`/Breaker#Failure().(timescip-go gomod github.com/golang/go/src go1.17 time/.Sincescip-go gomod github.com/golang/go/src go1.17 time/Since().(begin)) |
| 31 | } |
| 32 | }(timescip-go gomod github.com/golang/go/src go1.17 time/.Nowscip-go gomod github.com/golang/go/src go1.17 time/Now().()) |
| 33 | |
| 34 | response, err = next(ctx, request) |
| 35 | return |
| 36 | } |
| 37 | } |
| 38 | } |