Skip to content

Commit

Permalink
fix according review
Browse files Browse the repository at this point in the history
  • Loading branch information
xujianhai666 committed Sep 18, 2019
1 parent 1d85806 commit bb37d14
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
14 changes: 6 additions & 8 deletions filter/impl/token_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ import (
)

const (
token = "token"
TOKEN = "token"
)

func init() {
extension.SetFilter(token, GetTokenFilter)
extension.SetFilter(TOKEN, GetTokenFilter)
}

type TokenFilter struct{}
Expand All @@ -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())}
}

Expand Down
13 changes: 2 additions & 11 deletions protocol/dubbo/dubbo_invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand All @@ -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)
}
}
Expand Down

0 comments on commit bb37d14

Please sign in to comment.