forked from gojek/heimdall
/
config.go
39 lines (34 loc) · 1.14 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package heimdall
import (
"github.com/afex/hystrix-go/hystrix"
)
type fallbackFunc func(error) error
// HystrixConfig is used to pass configurations for Hystrix
type HystrixConfig struct {
commandName string
commandConfig hystrix.CommandConfig
fallbackFunc fallbackFunc
}
// HystrixCommandConfig takes the hystrix config values
type HystrixCommandConfig struct {
Timeout int
MaxConcurrentRequests int
RequestVolumeThreshold int
SleepWindow int
ErrorPercentThreshold int
FallbackFunc fallbackFunc
}
// NewHystrixConfig should be used to give hystrix commandName and config
func NewHystrixConfig(commandName string, commandConfig HystrixCommandConfig) HystrixConfig {
return HystrixConfig{
commandName: commandName,
commandConfig: hystrix.CommandConfig{
Timeout: commandConfig.Timeout,
MaxConcurrentRequests: commandConfig.MaxConcurrentRequests,
RequestVolumeThreshold: commandConfig.RequestVolumeThreshold,
SleepWindow: commandConfig.SleepWindow,
ErrorPercentThreshold: commandConfig.ErrorPercentThreshold,
},
fallbackFunc: commandConfig.FallbackFunc,
}
}