diff --git a/filter/impl/token_filter.go b/filter/impl/token_filter.go
index 6b658bed7c9517eaf31d8496be694373df764be3..8c42851c34563212e0208c67a70a4034b8a53dc1 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 1b736b1289f413de12c512ab75f20d162493604c..bc321a97a4271c147d9317145d9f1aa76ca27902 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)
}
}