From bb37d14e7fc8a818c4dcb38fa8a8c28866850f61 Mon Sep 17 00:00:00 2001 From: xujianhai666 <zero.xu@bytedance.com> Date: Tue, 17 Sep 2019 10:21:30 +0800 Subject: [PATCH] fix according review --- filter/impl/token_filter.go | 14 ++++++-------- protocol/dubbo/dubbo_invoker.go | 13 ++----------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/filter/impl/token_filter.go b/filter/impl/token_filter.go index 6b658bed7..8c42851c3 100644 --- a/filter/impl/token_filter.go +++ b/filter/impl/token_filter.go @@ -33,11 +33,11 @@ import ( ) const ( - token = "token" + TOKEN = "token" ) func init() { - extension.SetFilter(token, GetTokenFilter) + extension.SetFilter(TOKEN, GetTokenFilter) } type TokenFilter struct{} @@ -46,13 +46,11 @@ func (tf *TokenFilter) Invoke(invoker protocol.Invoker, invocation protocol.Invo invokerTkn := invoker.GetUrl().GetParam(constant.TOKEN_KEY, "") if len(invokerTkn) > 0 { attachs := invocation.Attachments() - if len(attachs) > 0 { - remoteTkn, exist := attachs[constant.TOKEN_KEY] - if exist && strings.EqualFold(invokerTkn, remoteTkn) { - return invoker.Invoke(invocation) - } + remoteTkn, exist := attachs[constant.TOKEN_KEY] + if exist && strings.EqualFold(invokerTkn, remoteTkn) { + return invoker.Invoke(invocation) } - return &protocol.RPCResult{Err: perrors.Errorf("Invalid token! Forbid invoke remote service %s method %s ", + return &protocol.RPCResult{Err: perrors.Errorf("Invalid token! Forbid invoke remote service %v method %s ", invoker, invocation.MethodName())} } diff --git a/protocol/dubbo/dubbo_invoker.go b/protocol/dubbo/dubbo_invoker.go index 1b736b128..bc321a97a 100644 --- a/protocol/dubbo/dubbo_invoker.go +++ b/protocol/dubbo/dubbo_invoker.go @@ -43,22 +43,13 @@ var ( type DubboInvoker struct { protocol.BaseInvoker client *Client - attachment map[string]string destroyLock sync.Mutex } func NewDubboInvoker(url common.URL, client *Client) *DubboInvoker { - attachment := make(map[string]string, 0) - for _, k := range attachmentKey { - if v := url.GetParam(k, ""); len(v) > 0 { - attachment[k] = v - } - } - return &DubboInvoker{ BaseInvoker: *protocol.NewBaseInvoker(url), client: client, - attachment: attachment, } } @@ -70,8 +61,8 @@ func (di *DubboInvoker) Invoke(invocation protocol.Invocation) protocol.Result { ) inv := invocation.(*invocation_impl.RPCInvocation) - if len(di.attachment) > 0 { - for k, v := range di.attachment { + for _, k := range attachmentKey { + if v := di.GetUrl().GetParam(k, ""); len(v) > 0 { inv.SetAttachments(k, v) } } -- GitLab