No-SilverBullet commented on code in PR #2828:
URL: https://github.com/apache/dubbo-go/pull/2828#discussion_r2030916503


##########
protocol/triple/client.go:
##########
@@ -70,6 +70,16 @@ func (cm *clientManager) callUnary(ctx context.Context, 
method string, req, resp
        if err := triClient.CallUnary(ctx, triReq, triResp); err != nil {
                return err
        }
+       val := ctx.Value(constant.AttachmentKey)
+       if val != nil {
+               if attachments, ok := val.(map[string]interface{}); ok {
+                       for k, v := range triResp.Trailer() {
+                               if len(v) > 0 {
+                                       attachments[k] = v[0]
+                               }
+                       }
+               }

Review Comment:
   put `if attachments, ok := val.(map[string]interface{}); ok` outside, cause 
too much nesting, like this
   attachments, ok := val.(map[string]interface{})
   if !ok {
       return nil
   }
   
   for k, v := range triResp.Trailer() {
       if len(v) > 0 {
           attachments[k] = v[0]
       }
   }



##########
protocol/triple/server.go:
##########
@@ -247,8 +247,24 @@ func (s *Server) handleServiceWithInfo(interfaceName 
string, invoker protocol.In
                                        attachments := 
generateAttachments(req.Header())
                                        // inject attachments
                                        ctx = context.WithValue(ctx, 
constant.AttachmentKey, attachments)
+                                       oldAttachments := 
map[string]interface{}{}

Review Comment:
   use `make` to initialize map



##########
protocol/triple/server.go:
##########
@@ -247,8 +247,24 @@ func (s *Server) handleServiceWithInfo(interfaceName 
string, invoker protocol.In
                                        attachments := 
generateAttachments(req.Header())
                                        // inject attachments
                                        ctx = context.WithValue(ctx, 
constant.AttachmentKey, attachments)
+                                       oldAttachments := 
map[string]interface{}{}
+                                       if original, ok := 
ctx.Value(constant.AttachmentKey).(map[string]interface{}); ok {
+                                               for k, v := range original {
+                                                       oldAttachments[k] = v
+                                               }
+                                       }
                                        invo := 
invocation.NewRPCInvocation(m.Name, args, attachments)
                                        res := invoker.Invoke(ctx, invo)
+                                       newAttachments, _ := 
ctx.Value(constant.AttachmentKey).(map[string]interface{})

Review Comment:
   do not ignore this error, may cause panic.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to