2020-05-10 17:03:24 +03:00
|
|
|
package circuit
|
|
|
|
|
|
|
|
import "time"
|
|
|
|
|
|
|
|
//Options for breaker
|
|
|
|
type Options struct {
|
2020-05-11 09:31:25 +03:00
|
|
|
Name string
|
|
|
|
Expiry time.Time
|
|
|
|
Interval, Timeout time.Duration
|
|
|
|
MaxRequests uint32
|
|
|
|
ReadyToTrip StateCheckerHandler
|
|
|
|
OnStateChanged StateChangedEventHandler
|
2020-05-10 17:03:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//SetName of breaker
|
|
|
|
func SetName(name string) Option {
|
|
|
|
return func(opts *Options) {
|
|
|
|
opts.Name = name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//SetExpiry of breaker
|
|
|
|
func SetExpiry(expiry time.Time) Option {
|
|
|
|
return func(opts *Options) {
|
|
|
|
opts.Expiry = expiry
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//SetStateChangedHandle set handle of ChangedHandle
|
|
|
|
func SetStateChangedHandle(handler StateChangedEventHandler) Option {
|
|
|
|
return func(opts *Options) {
|
|
|
|
opts.OnStateChanged = handler
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//SetReadyToTrip check traffic state ,to see if request can go
|
|
|
|
func SetReadyToTrip(readyToGo StateCheckerHandler) Option {
|
|
|
|
return func(opts *Options) {
|
|
|
|
opts.ReadyToTrip = readyToGo
|
|
|
|
}
|
|
|
|
}
|