diff --git a/examples/dubbo/with-hystrix-go-client/app/example_hystrix_fallback.go b/examples/dubbo/with-hystrix-go-client/app/example_hystrix_fallback.go index 2faf687e5fe8353e11d405fe4441e3fd47ca785b..dd9111659c0c58aa736b72aa90034bc161dac833 100644 --- a/examples/dubbo/with-hystrix-go-client/app/example_hystrix_fallback.go +++ b/examples/dubbo/with-hystrix-go-client/app/example_hystrix_fallback.go @@ -8,7 +8,6 @@ import "github.com/afex/hystrix-go/hystrix" const EXAMPLE_FALLBACK_NAME = "exampleFallback" - type ExampleHystrixFallback struct { } @@ -18,7 +17,7 @@ type ExampleHystrixFallback struct { //The invoker that the filter receives; //The invocation that should be invoked; //The copy of circuit breaker for this invocation, for getting its status -func(f *ExampleHystrixFallback) FallbackFunc (err error, invoker protocol.Invoker, invocation protocol.Invocation, cb hystrix.CircuitBreaker) protocol.Result { +func (f *ExampleHystrixFallback) FallbackFunc(err error, invoker protocol.Invoker, invocation protocol.Invocation, cb hystrix.CircuitBreaker) protocol.Result { result := &protocol.RPCResult{} if cb.IsOpen() { result.SetError(nil) @@ -29,7 +28,6 @@ func(f *ExampleHystrixFallback) FallbackFunc (err error, invoker protocol.Invoke return result } - //Add the fallback function to the map //The name MUST be the same as in your config file func init() { diff --git a/filter/impl/default_hystrix_fallback.go b/filter/impl/default_hystrix_fallback.go index a5284e1c27671a7452426982d7a97b075971ea23..d45a672d4830d8bd12fc011ceb2968b5309c548e 100644 --- a/filter/impl/default_hystrix_fallback.go +++ b/filter/impl/default_hystrix_fallback.go @@ -7,9 +7,10 @@ import ( type DefaultHystrixFallback struct { } -func(d *DefaultHystrixFallback) FallbackFunc(err error, invoker protocol.Invoker, invocation protocol.Invocation, cb hystrix.CircuitBreaker) protocol.Result{ + +func (d *DefaultHystrixFallback) FallbackFunc(err error, invoker protocol.Invoker, invocation protocol.Invocation, cb hystrix.CircuitBreaker) protocol.Result { //By default, return nil value and the error occurred res := &protocol.RPCResult{} res.SetError(err) return res -} \ No newline at end of file +} diff --git a/filter/impl/hystrix_filter.go b/filter/impl/hystrix_filter.go index 978f15e5b04e65c17859f6d96c5dcce60c39e931..1cdcbc670ed9dc1d2bfe1e253eb85c3db1c54e5b 100644 --- a/filter/impl/hystrix_filter.go +++ b/filter/impl/hystrix_filter.go @@ -74,7 +74,7 @@ func (hf *HystrixFilter) Invoke(invoker protocol.Invoker, invocation protocol.In return result.Error() }, func(err error) error { //failure logic - logger.Debugf("[Hystrix Filter]Invoke failed, error is: %v, circuit breaker open: %v",err, cb.IsOpen()) + logger.Debugf("[Hystrix Filter]Invoke failed, error is: %v, circuit breaker open: %v", err, cb.IsOpen()) result = hf.fallback.FallbackFunc(err, invoker, invocation, *cb) //If user try to return nil in the customized fallback func, it will cause panic @@ -131,7 +131,7 @@ func getConfig(service string, method string) CommandConfigWithFallback { } func initHystrixConfig() error { - if config.GetConsumerConfig().FilterConf == nil{ + if config.GetConsumerConfig().FilterConf == nil { return perrors.Errorf("no config for hystrix") } filterConfig := config.GetConsumerConfig().FilterConf.(map[interface{}]interface{})[HYSTRIX] diff --git a/filter/impl/hystrix_filter_test.go b/filter/impl/hystrix_filter_test.go index 380afa5cc6bdf7180b8bba654b50f1a4e559cbae..d3bf89bce4807be38412d7784ea4eec8f78e711b 100644 --- a/filter/impl/hystrix_filter_test.go +++ b/filter/impl/hystrix_filter_test.go @@ -11,18 +11,18 @@ import ( "time" ) -func init(){ +func init() { mockInitHystrixConfig() } -func mockInitHystrixConfig(){ +func mockInitHystrixConfig() { //Mock config - conf=&HystrixFilterConfig{ + conf = &HystrixFilterConfig{ make(map[string]*CommandConfigWithFallback), "Default", make(map[string]ServiceHystrixConfig), } - conf.Configs["Default"]= &CommandConfigWithFallback{ + conf.Configs["Default"] = &CommandConfigWithFallback{ 1000, 10, 20, @@ -30,7 +30,7 @@ func mockInitHystrixConfig(){ 50, "", } - conf.Configs["userp"]=&CommandConfigWithFallback{ + conf.Configs["userp"] = &CommandConfigWithFallback{ 2000, 8, 15, @@ -38,19 +38,18 @@ func mockInitHystrixConfig(){ 45, "", } - conf.Configs["userp_m"]=&CommandConfigWithFallback{ + conf.Configs["userp_m"] = &CommandConfigWithFallback{ 1200, 12, 5, 6000, 60, "exampleFallback", - } - conf.Services["com.ikurento.user.UserProvider"]=ServiceHystrixConfig{ + conf.Services["com.ikurento.user.UserProvider"] = ServiceHystrixConfig{ "userp", - map[string] string{ - "GetUser":"userp_m", + map[string]string{ + "GetUser": "userp_m", }, } @@ -107,7 +106,7 @@ func TestGetHystrixFallback(t *testing.T) { fallbackGot := getHystrixFallback("mock") assert.NotNil(t, fallbackGot) fallbackGot = getHystrixFallback("notExist") - assert.IsType(t,&DefaultHystrixFallback{},fallbackGot) + assert.IsType(t, &DefaultHystrixFallback{}, fallbackGot) } func TestDefaultHystrixFallback_FallbackFunc(t *testing.T) { diff --git a/protocol/protocolwrapper/protocol_filter_wrapper_test.go b/protocol/protocolwrapper/protocol_filter_wrapper_test.go index c7b2823a91fa15062c5fb26f664ef1dbf1e6b3dc..e0eb3c5514e3b1c9395fcc626d1e2ce36734f68f 100644 --- a/protocol/protocolwrapper/protocol_filter_wrapper_test.go +++ b/protocol/protocolwrapper/protocol_filter_wrapper_test.go @@ -36,11 +36,13 @@ import ( ) //To avoid import cycle -const( +const ( MOCK = "mock" ) + type MockFilter struct { } + func (mf *MockFilter) Invoke(invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result { return invoker.Invoke(invocation) } @@ -49,12 +51,12 @@ func (mf *MockFilter) OnResponse(result protocol.Result, invoker protocol.Invoke return result } -func GetFilter()filter.Filter{ +func GetFilter() filter.Filter { return &MockFilter{} } -func init(){ - extension.SetFilter(MOCK,GetFilter) +func init() { + extension.SetFilter(MOCK, GetFilter) } func TestProtocolFilterWrapper_Export(t *testing.T) {