You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "1kasa (via GitHub)" <gi...@apache.org> on 2025/03/31 09:36:28 UTC

[PR] fix: Support the use of new API to support two-way transfer of attchment [dubbo-go-samples]

1kasa opened a new pull request, #821:
URL: https://github.com/apache/dubbo-go-samples/pull/821

   Support the use of new API to support two-way transfer of attchment


-- 
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: notifications-unsubscribe@dubbo.apache.org

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


Re: [PR] fix: Support the use of new API to support two-way transfer of attchment [dubbo-go-samples]

Posted by "No-SilverBullet (via GitHub)" <gi...@apache.org>.
No-SilverBullet commented on code in PR #821:
URL: https://github.com/apache/dubbo-go-samples/pull/821#discussion_r2020879193


##########
context/go-client/cmd/main.go:
##########
@@ -40,15 +41,27 @@ func main() {
 		panic(err)
 	}
 
-	ctx := context.Background()
-	ctx = context.WithValue(ctx, constant.AttachmentKey, map[string]interface{}{
-		"key1": "user defined value 1",
-		"key2": "user defined value 2",
-	})
+	header := http.Header{"testKey1": []string{"testVal1"}, "testKey2": []string{"testVal2"}}
+	// to store outgoing data ,and reserve the location for the receive field.
+	// header will be copy , and header's key will change to be lowwer.
+	ctx := triple_protocol.NewOutgoingContext(context.Background(), header)
+	ctx = triple_protocol.AppendToOutgoingContext(ctx, "testKey3", "testVal3")
 
 	resp, err := svc.Greet(ctx, &greet.GreetRequest{Name: "hello world"})
 	if err != nil {
 		logger.Error(err)
 	}
+	extractedHeader, _ := triple_protocol.FromIncomingContext(ctx)
+
+	var value1, value2 string
+	if values, ok := extractedHeader["outgoingcontextkey1"]; ok && len(values) > 0 {

Review Comment:
   http header should be Canonical, rename it to `OutgoingContextKey1` or use http.CanonicalHeaderKey(); same as other header keys should be modified too. 



-- 
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: notifications-unsubscribe@dubbo.apache.org

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


Re: [PR] fix: Support the use of new API to support two-way transfer of attachment [dubbo-go-samples]

Posted by "1kasa (via GitHub)" <gi...@apache.org>.
1kasa closed pull request #821: fix: Support the use of new API to support two-way transfer of attachment
URL: https://github.com/apache/dubbo-go-samples/pull/821


-- 
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: notifications-unsubscribe@dubbo.apache.org

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


Re: [PR] fix: Support the use of new API to support two-way transfer of attachment [dubbo-go-samples]

Posted by "1kasa (via GitHub)" <gi...@apache.org>.
1kasa closed pull request #821: fix: Support the use of new API to support two-way transfer of attachment
URL: https://github.com/apache/dubbo-go-samples/pull/821


-- 
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: notifications-unsubscribe@dubbo.apache.org

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


Re: [PR] fix: Support the use of new API to support two-way transfer of attchment [dubbo-go-samples]

Posted by "FoghostCn (via GitHub)" <gi...@apache.org>.
FoghostCn commented on code in PR #821:
URL: https://github.com/apache/dubbo-go-samples/pull/821#discussion_r2020737235


##########
context/README.md:
##########
@@ -76,15 +78,24 @@ type GreetTripleServer struct {
 }
 
 func (srv *GreetTripleServer) Greet(ctx context.Context, req *greet.GreetRequest) (*greet.GreetResponse, error) {
-	attachments := ctx.Value(constant.AttachmentKey).(map[string]interface{})
-	if value1, ok := attachments["key1"]; ok {
-		logger.Infof("Dubbo attachment key1 = %s", value1.([]string)[0])
+	data, _ := triple.FromIncomingContext(ctx)
+	ctx = triple.AppendToOutgoingContext(ctx, "OutgoingContextKey1", "OutgoingDataVal1", "OutgoingContextKey2", "OutgoingDataVal2")

Review Comment:
   ditto



##########
context/README.md:
##########
@@ -7,22 +7,22 @@ This sample demonstrates how to use context to pass and read additional paramete
 ## 2.How to Pass Additional Parameters
 ### 2.1 Client
 
-You can pass context parameters to the server by using `context.WithValue` function. Note that the key needs to be fixed to "attachment".
+You can pass context parameters to the server by using `triple_protocol.AppendToOutgoingContext` function. Note that the key needs to be fixed to "attachment".
 
 ```go
-	ctx := context.Background()
-	ctx = context.WithValue(ctx, constant.AttachmentKey, map[string]interface{}{
-        "key1": "user defined value 1",
-        "key2": "user defined value 2"
-	})
+    header := http.Header{"testKey1": []string{"testVal1"}, "testKey2": []string{"testVal2"}}
+    // to store outgoing data ,and reserve the location for the receive field.
+    // header will be copy , and header's key will change to be lowwer.
+	ctx := triple_protocol.NewOutgoingContext(context.Background(), header)
+    ctx = triple_protocol.AppendToOutgoingContext(ctx, "testKey3", "testVal3")

Review Comment:
   These APIs are private to the triple protocol and should not be exposed to users. we should try to use the common APIs for all protocol,such as:
   
   ```
   atta := ctx.Value(constant.AttachmentKey)
   ctx = context.WithValue(ctx, constant.AttachmentKey, attachments)
   ```



##########
context/README.md:
##########
@@ -7,22 +7,22 @@ This sample demonstrates how to use context to pass and read additional paramete
 ## 2.How to Pass Additional Parameters
 ### 2.1 Client
 
-You can pass context parameters to the server by using `context.WithValue` function. Note that the key needs to be fixed to "attachment".
+You can pass context parameters to the server by using `triple_protocol.AppendToOutgoingContext` function. Note that the key needs to be fixed to "attachment".
 
 ```go
-	ctx := context.Background()
-	ctx = context.WithValue(ctx, constant.AttachmentKey, map[string]interface{}{
-        "key1": "user defined value 1",
-        "key2": "user defined value 2"
-	})
+    header := http.Header{"testKey1": []string{"testVal1"}, "testKey2": []string{"testVal2"}}
+    // to store outgoing data ,and reserve the location for the receive field.
+    // header will be copy , and header's key will change to be lowwer.
+	ctx := triple_protocol.NewOutgoingContext(context.Background(), header)
+    ctx = triple_protocol.AppendToOutgoingContext(ctx, "testKey3", "testVal3")
 ```
 
 ### 2.2 Server
 
-You can get context parameters from the client by using `context.Value` function. Note that the key needs to be fixed to "attachment" and the value type is []string.
+You can get context parameters from the client by using `triple.FromIncomingContext` function. Note that the key is the key confirmed by the sender and the value type is []string.
 
 ```go
-    attachments := ctx.Value(constant.AttachmentKey).(map[string]interface{})
+    data, _ := triple.FromIncomingContext(ctx)

Review Comment:
   ditto



##########
integrate_test/context/tests/integration/context_test.go:
##########
@@ -19,25 +19,37 @@ package integration
 
 import (
 	"context"
+	"dubbo.apache.org/dubbo-go/v3/protocol/triple/triple_protocol"
+	"net/http"
 	"testing"
 
-	"dubbo.apache.org/dubbo-go/v3/common/constant"
 	greet "github.com/apache/dubbo-go-samples/context/proto"
 	"github.com/stretchr/testify/assert"
 )
 
 func TestSayHello(t *testing.T) {
 	req := &greet.GreetRequest{Name: "hello world"}
 
-	ctx := context.Background()
-	ctx = context.WithValue(ctx, constant.AttachmentKey, map[string]interface{}{
-		"key1": "value1",
-		"key2": "value2",
-		"key3": "value3",
-	})
+	header := http.Header{"testKey1": []string{"testVal1"}, "testKey2": []string{"testVal2"}}
+	// to store outgoing data ,and reserve the location for the receive field.
+	// header will be copy , and header's key will change to be lowwer.
+	ctx := triple_protocol.NewOutgoingContext(context.Background(), header)
+	ctx = triple_protocol.AppendToOutgoingContext(ctx, "testKey3", "testVal3")

Review Comment:
   ditto for all



-- 
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: notifications-unsubscribe@dubbo.apache.org

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


Re: [PR] fix: Support the use of new API to support two-way transfer of attchment [dubbo-go-samples]

Posted by "AlexStocks (via GitHub)" <gi...@apache.org>.
AlexStocks commented on code in PR #821:
URL: https://github.com/apache/dubbo-go-samples/pull/821#discussion_r2020821115


##########
context/README.md:
##########
@@ -64,7 +64,9 @@ package main
 
 import (

Review Comment:
   像其他地方一样,把 import 拆成 3 个 block



-- 
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: notifications-unsubscribe@dubbo.apache.org

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


Re: [PR] fix: Support the use of new API to support two-way transfer of attchment [dubbo-go-samples]

Posted by "AlexStocks (via GitHub)" <gi...@apache.org>.
AlexStocks commented on code in PR #821:
URL: https://github.com/apache/dubbo-go-samples/pull/821#discussion_r2020821709


##########
integrate_test/context/tests/integration/context_test.go:
##########
@@ -19,25 +19,37 @@ package integration
 
 import (

Review Comment:
   import 模块乱了



-- 
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: notifications-unsubscribe@dubbo.apache.org

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