ax(mining): replace prose comments with usage examples in circuit_breaker.go
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run

AX Principle 2 — comments as usage examples, not prose descriptions.
DefaultCircuitBreakerConfig, NewCircuitBreaker, State, Reset, GetCached
all had comments that restated the signature; replaced with concrete call examples.

Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
Claude 2026-04-02 08:21:34 +01:00
parent 0d9071d528
commit 7396ef0253
No known key found for this signature in database
GPG key ID: AF404715446AEB41

View file

@ -42,7 +42,8 @@ type CircuitBreakerConfig struct {
SuccessThreshold int
}
// DefaultCircuitBreakerConfig returns sensible defaults
// cfg := DefaultCircuitBreakerConfig()
// cb := NewCircuitBreaker("github-api", cfg)
func DefaultCircuitBreakerConfig() CircuitBreakerConfig {
return CircuitBreakerConfig{
FailureThreshold: 3,
@ -70,7 +71,7 @@ type CircuitBreaker struct {
// if err == ErrCircuitOpen { /* fallback to cached result */ }
var ErrCircuitOpen = NewMiningError(ErrCodeServiceUnavailable, "circuit breaker is open")
// NewCircuitBreaker creates a new circuit breaker
// cb := NewCircuitBreaker("github-api", DefaultCircuitBreakerConfig())
func NewCircuitBreaker(name string, config CircuitBreakerConfig) *CircuitBreaker {
return &CircuitBreaker{
name: name,
@ -80,7 +81,7 @@ func NewCircuitBreaker(name string, config CircuitBreakerConfig) *CircuitBreaker
}
}
// State returns the current circuit state
// if cb.State() == CircuitOpen { return nil, ErrCircuitOpen }
func (cb *CircuitBreaker) State() CircuitState {
cb.mu.RLock()
defer cb.mu.RUnlock()
@ -203,7 +204,7 @@ func (cb *CircuitBreaker) recordSuccess(result interface{}) {
}
}
// Reset manually resets the circuit breaker to closed state
// cb.Reset() // force closed state after maintenance window
func (cb *CircuitBreaker) Reset() {
cb.mu.Lock()
defer cb.mu.Unlock()
@ -216,7 +217,7 @@ func (cb *CircuitBreaker) Reset() {
})
}
// GetCached returns the cached result if available
// if result, ok := cb.GetCached(); ok { return result, nil }
func (cb *CircuitBreaker) GetCached() (interface{}, bool) {
cb.mu.RLock()
defer cb.mu.RUnlock()