You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2020/05/24 11:06:03 UTC

[GitHub] [dubbo-go] AlexStocks commented on a change in pull request #537: Add attribute method into Invocation and RpcInvocation

AlexStocks commented on a change in pull request #537:
URL: https://github.com/apache/dubbo-go/pull/537#discussion_r429624713



##########
File path: protocol/invocation/rpcinvocation.go
##########
@@ -40,8 +40,10 @@ type RPCInvocation struct {
 	reply           interface{}
 	callBack        interface{}
 	attachments     map[string]string
-	invoker         protocol.Invoker
-	lock            sync.RWMutex
+	// Refer to dubbo 2.7.6.  It is different from attachment. It is used in internal process.
+	attributes map[string]interface{}

Review comment:
       @cvictory pls remember that: when u define a map/slice/chan in a struct , u should init it by `make(map[string]interface{}, 8)` in NewRPCInvocation. If not, the program will panic when u visit or write this map.

##########
File path: protocol/invocation/rpcinvocation.go
##########
@@ -111,6 +113,25 @@ func (r *RPCInvocation) AttachmentsByKey(key string, defaultValue string) string
 	return defaultValue
 }
 
+// get attributes
+func (r *RPCInvocation) Attributes() map[string]interface{} {
+	return r.attributes
+}
+
+// get attribute by key. If it is not exist, it will return default value
+func (r *RPCInvocation) AttributeByKey(key string, defaultValue interface{}) interface{} {
+	r.lock.RLock()
+	defer r.lock.RUnlock()
+	if r.attributes == nil {

Review comment:
       after init this map in newRPCInvocation, u can delete this if condition clause.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org