newCircuitBreaker creates a new circuit breaker for an endpoint
(endpoint string, config *Config)
| 57 | |
| 58 | // newCircuitBreaker creates a new circuit breaker for an endpoint |
| 59 | func newCircuitBreaker(endpoint string, config *Config) *CircuitBreaker { |
| 60 | // Use configuration values with sensible defaults |
| 61 | failureThreshold := 5 |
| 62 | resetTimeout := 60 * time.Second |
| 63 | maxRequests := 3 |
| 64 | |
| 65 | if config != nil { |
| 66 | failureThreshold = config.CircuitBreakerFailureThreshold |
| 67 | resetTimeout = config.CircuitBreakerResetTimeout |
| 68 | maxRequests = config.CircuitBreakerMaxRequests |
| 69 | } |
| 70 | |
| 71 | return &CircuitBreaker{ |
| 72 | failureThreshold: failureThreshold, |
| 73 | resetTimeout: resetTimeout, |
| 74 | maxRequests: maxRequests, |
| 75 | endpoint: endpoint, |
| 76 | config: config, |
| 77 | state: atomic.Int32{}, // Defaults to CircuitBreakerClosed (0) |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | // IsOpen returns true if the circuit breaker is open (rejecting requests) |
| 82 | func (cb *CircuitBreaker) IsOpen() bool { |
no outgoing calls