From c50bd5a87ccc3f0d41383cb89aaaa1642b855b5c Mon Sep 17 00:00:00 2001 From: YGrylls <910357107@qq.com> Date: Mon, 22 Jul 2019 15:53:49 +0800 Subject: [PATCH] fmt --- .../app/example_hystrix_fallback.go | 4 +--- filter/impl/default_hystrix_fallback.go | 5 +++-- filter/impl/hystrix_filter.go | 4 ++-- filter/impl/hystrix_filter_test.go | 21 +++++++++---------- .../protocol_filter_wrapper_test.go | 10 +++++---- 5 files changed, 22 insertions(+), 22 deletions(-) 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 2faf687e5..dd9111659 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 a5284e1c2..d45a672d4 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 978f15e5b..1cdcbc670 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 380afa5cc..d3bf89bce 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 c7b2823a9..e0eb3c551 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) { -- GitLab