From a78109fa7939a7e5bf81759cb045ca63f0cf1c6f Mon Sep 17 00:00:00 2001 From: cvictory <shenglicao2@gmail.com> Date: Sun, 24 May 2020 19:20:40 +0800 Subject: [PATCH] add default value of attribute --- protocol/invocation/rpcinvocation.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/protocol/invocation/rpcinvocation.go b/protocol/invocation/rpcinvocation.go index 10c0efe9c..35474e54e 100644 --- a/protocol/invocation/rpcinvocation.go +++ b/protocol/invocation/rpcinvocation.go @@ -52,6 +52,7 @@ func NewRPCInvocation(methodName string, arguments []interface{}, attachments ma methodName: methodName, arguments: arguments, attachments: attachments, + attributes: make(map[string]interface{}, 8), } } @@ -142,6 +143,16 @@ func (r *RPCInvocation) SetAttachments(key string, value string) { r.attachments[key] = value } +// SetAttribute. If Attributes is nil, it will be inited. +func (r *RPCInvocation) SetAttribute(key string, value interface{}) { + r.lock.Lock() + defer r.lock.Unlock() + if r.attributes == nil { + r.attributes = make(map[string]interface{}) + } + r.attributes[key] = value +} + // Invoker ... func (r *RPCInvocation) Invoker() protocol.Invoker { return r.invoker @@ -217,6 +228,12 @@ func WithAttachments(attachments map[string]string) option { } } +func WithAttributes(attributes map[string]interface{}) option { + return func(invo *RPCInvocation) { + invo.attributes = attributes + } +} + // WithInvoker ... func WithInvoker(invoker protocol.Invoker) option { return func(invo *RPCInvocation) { -- GitLab