1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-04-04 20:44:27 +02:00
Johnson C 44ecd6a457
Hystrix filter (#2286)
* support hystrix filter

* filter function should return true of false
2021-09-28 11:23:04 +01:00

30 lines
801 B
Go

package hystrix
import "context"
// Options represents hystrix client wrapper options
type Options struct {
// Filter used to prevent errors from trigger circuit breaker.
// return true if you want to ignore target error
Filter func(context.Context, error) bool
// Fallback used to define some code to execute during outages.
Fallback func(context.Context, error) error
}
// Option represents options update func
type Option func(*Options)
// WithFilter used to set filter func for options
func WithFilter(filter func(context.Context, error) bool) Option {
return func(o *Options) {
o.Filter = filter
}
}
// WithFallback used to set fallback func for options
func WithFallback(fallback func(context.Context, error) error) Option {
return func(o *Options) {
o.Fallback = fallback
}
}