Skip to content
Snippets Groups Projects
Commit bc075607 authored by xujianhai666's avatar xujianhai666
Browse files

fix according review

parent 206bdca9
No related branches found
No related tags found
No related merge requests found
......@@ -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())}
}
......
......@@ -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)
}
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment