func (cb *ConsecCircuitBreaker) Call(fn func() error, d time.Duration) error {
	var err error
	if !cb.ready() {
		return ErrBreakerOpen
	}
	if d == 0 {
		err = fn()
	} else {
		c := make(chan error, 1)
		go func() {
			c <- fn()
			close(c)
		}()
		t := time.NewTimer(d)
		select {
		case e := <-c:
			err = e
		case <-t.C:
			err = ErrBreakerTimeout
		}
		t.Stop()
	}
	if err == nil {
		cb.success()
	} else {
		cb.fail()
	}
	return err
}
Call Circuit function
package client
import (
	"errors"
	"sync/atomic"
	"time"
)
var (
	ErrBreakerOpen    = errors.New("breaker open")
	ErrBreakerTimeout = errors.New("breaker time out")
)
type ConsecCircuitBreaker struct {
	lastFailureTime  time.Time
	failures         uint64
	failureThreshold uint64
	window           time.Duration
}
func NewConsecCircuitBreaker(failureThreshold uint64, window time.Duration) *ConsecCircuitBreaker {
	return &ConsecCircuitBreaker{
		failureThreshold: failureThreshold,
		window:           window,
	}
}