diff --git a/config/consumer_config.go b/config/consumer_config.go
index 67d767896d7edab38e2868de632aa0b53d52a9bb..32c3ce167cf5685203170e347e17aad7eed044f9 100644
--- a/config/consumer_config.go
+++ b/config/consumer_config.go
@@ -52,7 +52,7 @@ type ConsumerConfig struct {
Registries map[string]*RegistryConfig `yaml:"registries" json:"registries,omitempty" property:"registries"`
References map[string]*ReferenceConfig `yaml:"references" json:"references,omitempty" property:"references"`
ProtocolConf interface{} `yaml:"protocol_conf" json:"protocol_conf,omitempty" property:"protocol_conf"`
- FilterConf interface{} `yaml:"filter_conf" json:"filter_conf,omitempty" property:"filter_conf" `
+ FilterConf interface{} `yaml:"filter_conf" json:"filter_conf,omitempty" property:"filter_conf" `
}
func (*ConsumerConfig) Prefix() string {
diff --git a/config/provider_config.go b/config/provider_config.go
index 780f48f2352abc33ccf35103a4d1300880654eef..aa9b551dfa8abd299b813d8cb5b3af598e86fd5a 100644
--- a/config/provider_config.go
+++ b/config/provider_config.go
@@ -46,7 +46,7 @@ type ProviderConfig struct {
Services map[string]*ServiceConfig `yaml:"services" json:"services,omitempty" property:"services"`
Protocols map[string]*ProtocolConfig `yaml:"protocols" json:"protocols,omitempty" property:"protocols"`
ProtocolConf interface{} `yaml:"protocol_conf" json:"protocol_conf,omitempty" property:"protocol_conf" `
- FilterConf interface{} `yaml:"filter_conf" json:"filter_conf,omitempty" property:"filter_conf" `
+ FilterConf interface{} `yaml:"filter_conf" json:"filter_conf,omitempty" property:"filter_conf" `
}
func (*ProviderConfig) Prefix() string {
diff --git a/filter/impl/hystrix_filter.go b/filter/impl/hystrix_filter.go
index 0c4b909995c5517db48e7bd9ea762c83a14f1a87..37c59d92ee4833f593d8ce269f27cd377c5a00e4 100644
--- a/filter/impl/hystrix_filter.go
+++ b/filter/impl/hystrix_filter.go
@@ -12,16 +12,14 @@ import (
"gopkg.in/yaml.v2"
)
-
const (
- HYSTRIX="hystrix"
- TIMEOUT_KEY="timeout"
- MAXCONCURRENTREQUESTS_KEY="maxconcurrentrequests"
- SLEEPWINDOW_KEY="sleepwindow"
- ERRORPERCENTTHRESHOLD_KEY="errorpercentthreshold"
+ HYSTRIX = "hystrix"
+ TIMEOUT_KEY = "timeout"
+ MAXCONCURRENTREQUESTS_KEY = "maxconcurrentrequests"
+ SLEEPWINDOW_KEY = "sleepwindow"
+ ERRORPERCENTTHRESHOLD_KEY = "errorpercentthreshold"
)
-
var (
//Timeout
//MaxConcurrentRequests
@@ -29,36 +27,34 @@ var (
//SleepWindow
//ErrorPercentThreshold
isConfigLoaded = false
- conf = &HystrixFilterConfig{}
+ conf = &HystrixFilterConfig{}
//
-
-
)
-func init(){
- extension.SetFilter(HYSTRIX,GetHystrixFilter)
+func init() {
+ extension.SetFilter(HYSTRIX, GetHystrixFilter)
}
-type HystrixFilter struct {
+type HystrixFilter struct {
}
-func (hf *HystrixFilter) Invoke(invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result{
+func (hf *HystrixFilter) Invoke(invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
- cmdName := fmt.Sprintf("%s&method=%s",invoker.GetUrl().Key(),invocation.MethodName())
+ cmdName := fmt.Sprintf("%s&method=%s", invoker.GetUrl().Key(), invocation.MethodName())
- _,ifNew,err := hystrix.GetCircuit(cmdName)
- if err != nil{
- logger.Errorf("[Hystrix Filter]Errors occurred getting circuit for %s , will invoke without hystrix, error is: ",cmdName,err)
+ _, ifNew, err := hystrix.GetCircuit(cmdName)
+ if err != nil {
+ logger.Errorf("[Hystrix Filter]Errors occurred getting circuit for %s , will invoke without hystrix, error is: ", cmdName, err)
return invoker.Invoke(invocation)
}
// Do the configuration if the circuit breaker is created for the first time
if ifNew {
- hystrix.ConfigureCommand(cmdName,getConfig(invoker.GetUrl().Service(),invocation.MethodName()))
+ hystrix.ConfigureCommand(cmdName, getConfig(invoker.GetUrl().Service(), invocation.MethodName()))
}
- logger.Infof("[Hystrix Filter]Using hystrix filter: %s",cmdName)
+ logger.Infof("[Hystrix Filter]Using hystrix filter: %s", cmdName)
var result protocol.Result
_ = hystrix.Do(cmdName, func() error {
result = invoker.Invoke(invocation)
@@ -75,51 +71,50 @@ func (hf *HystrixFilter) Invoke(invoker protocol.Invoker, invocation protocol.In
return result
}
-func (hf *HystrixFilter) OnResponse(result protocol.Result, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result{
+func (hf *HystrixFilter) OnResponse(result protocol.Result, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
return result
}
-func GetHystrixFilter() filter.Filter{
+func GetHystrixFilter() filter.Filter {
//When first called, load the config in
- if !isConfigLoaded{
- if err:=initHystrixConfig();err!=nil{
- logger.Warnf("[Hystrix Filter]Config load failed, error is: %v , will use default",err)
+ if !isConfigLoaded {
+ if err := initHystrixConfig(); err != nil {
+ logger.Warnf("[Hystrix Filter]Config load failed, error is: %v , will use default", err)
}
- isConfigLoaded=true
+ isConfigLoaded = true
}
-
return &HystrixFilter{}
}
-func getConfig(service string, method string) hystrix.CommandConfig{
+func getConfig(service string, method string) hystrix.CommandConfig {
//Find method level config
- getConf:=conf.Configs[conf.Services[service].Methods[method]]
- if getConf!=nil{
- logger.Infof("[Hystrix Filter]Found method-level config for %s - %s",service,method)
+ getConf := conf.Configs[conf.Services[service].Methods[method]]
+ if getConf != nil {
+ logger.Infof("[Hystrix Filter]Found method-level config for %s - %s", service, method)
return *getConf
}
//Find service level config
- getConf=conf.Configs[conf.Services[service].ServiceConfig]
- if getConf!=nil{
- logger.Infof("[Hystrix Filter]Found service-level config for %s - %s",service,method)
+ getConf = conf.Configs[conf.Services[service].ServiceConfig]
+ if getConf != nil {
+ logger.Infof("[Hystrix Filter]Found service-level config for %s - %s", service, method)
return *getConf
}
//Find default config
- getConf=conf.Configs[conf.Default]
- if getConf!=nil{
- logger.Infof("[Hystrix Filter]Found global default config for %s - %s",service,method)
+ getConf = conf.Configs[conf.Default]
+ if getConf != nil {
+ logger.Infof("[Hystrix Filter]Found global default config for %s - %s", service, method)
return *getConf
}
- getConf=&hystrix.CommandConfig{}
- logger.Infof("[Hystrix Filter]No config found for %s - %s, using default",service,method)
+ getConf = &hystrix.CommandConfig{}
+ logger.Infof("[Hystrix Filter]No config found for %s - %s, using default", service, method)
return *getConf
}
-func initHystrixConfig() error{
+func initHystrixConfig() error {
filterConfig := config.GetConsumerConfig().FilterConf.(map[interface{}]interface{})[HYSTRIX]
- if filterConfig ==nil{
+ if filterConfig == nil {
return perrors.Errorf("no config for hystrix")
}
hystrixConfByte, err := yaml.Marshal(filterConfig)
@@ -133,14 +128,12 @@ func initHystrixConfig() error{
return nil
}
-
type HystrixFilterConfig struct {
- Configs map[string] *hystrix.CommandConfig
- Default string
- Services map[string] ServiceHystrixConfig
+ Configs map[string]*hystrix.CommandConfig
+ Default string
+ Services map[string]ServiceHystrixConfig
}
-type ServiceHystrixConfig struct{
- ServiceConfig string `yaml:"service_config,omitempty"`
- Methods map[string]string
+type ServiceHystrixConfig struct {
+ ServiceConfig string `yaml:"service_config,omitempty"`
+ Methods map[string]string
}
-