This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
The following commit(s) were added to refs/heads/develop by this push:
new e2256e270 fix(router): ensure invoker receive Provider's tag, fix type
bug (#3208)
e2256e270 is described below
commit e2256e2703bc8a739a608b2eb7c1a042294b1cd9
Author: yangpixi <[email protected]>
AuthorDate: Thu Feb 12 21:28:31 2026 +0800
fix(router): ensure invoker receive Provider's tag, fix type bug (#3208)
* fix(router): ensure invoker receive Provider's tag, fix type bug
* test: add string type unit test for generateInvocation
---
client/client.go | 9 +++++++--
client/client_test.go | 26 +++++++++++++++++++++++++-
registry/nacos/service_discovery.go | 2 ++
3 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/client/client.go b/client/client.go
index a296f14ea..e31fdc7f2 100644
--- a/client/client.go
+++ b/client/client.go
@@ -238,8 +238,13 @@ func generateInvocation(ctx context.Context, methodName
string, reqs []any, resp
}
if attaRaw := ctx.Value(constant.AttachmentKey); attaRaw != nil {
- if userAtta, ok := attaRaw.(map[string]any); ok {
- for key, val := range userAtta {
+ switch v := attaRaw.(type) {
+ case map[string]string:
+ for key, val := range v {
+ attachments[key] = val
+ }
+ case map[string]any:
+ for key, val := range v {
attachments[key] = val
}
}
diff --git a/client/client_test.go b/client/client_test.go
index 0904a27a1..4f9766f16 100644
--- a/client/client_test.go
+++ b/client/client_test.go
@@ -91,7 +91,7 @@ func TestGenerateInvocation(t *testing.T) {
require.Equal(t, []any{"foo", 1, &resp}, inv.ParameterRawValues())
}
-func TestGenerateInvocationWithContextAttachments(t *testing.T) {
+func TestGenerateInvocationWithContextAttachmentsAndAnyType(t *testing.T) {
var resp int
opts := &CallOptions{RequestTimeout: "1s", Retries: "2"}
@@ -115,6 +115,30 @@ func TestGenerateInvocationWithContextAttachments(t
*testing.T) {
require.Equal(t, "abc-123", inv.GetAttachmentInterface("traceID"))
}
+func TestGenerateInvocationWithContextAttachmentsAndStringType(t *testing.T) {
+ var resp int
+ opts := &CallOptions{RequestTimeout: "1s", Retries: "2"}
+
+ userAttachments := map[string]string{
+ "userKey1": "userValue1",
+ "userKey2": "12345",
+ "traceID": "abc-123",
+ }
+ ctx := context.WithValue(context.Background(), constant.AttachmentKey,
userAttachments)
+
+ inv, err := generateInvocation(ctx, "Echo", []any{"foo", 1}, &resp,
constant.CallUnary, opts)
+ require.NoError(t, err)
+
+ timeout, _ := inv.GetAttachment(constant.TimeoutKey)
+ retries, _ := inv.GetAttachment(constant.RetriesKey)
+ require.Equal(t, "1s", timeout)
+ require.Equal(t, "2", retries)
+
+ require.Equal(t, "userValue1", inv.GetAttachmentInterface("userKey1"))
+ require.Equal(t, "12345", inv.GetAttachmentInterface("userKey2"))
+ require.Equal(t, "abc-123", inv.GetAttachmentInterface("traceID"))
+}
+
func TestConnectionCallPassesOptions(t *testing.T) {
invRes := &result.RPCResult{}
invoker := &fakeInvoker{res: invRes}
diff --git a/registry/nacos/service_discovery.go
b/registry/nacos/service_discovery.go
index c9f3af608..5bd1d4612 100644
--- a/registry/nacos/service_discovery.go
+++ b/registry/nacos/service_discovery.go
@@ -194,6 +194,7 @@ func (n *nacosServiceDiscovery) GetInstances(serviceName
string) []registry.Serv
for _, ins := range instances {
metadata := ins.Metadata
id := metadata[idKey]
+ tag := metadata[constant.Tagkey]
delete(metadata, idKey)
@@ -209,6 +210,7 @@ func (n *nacosServiceDiscovery) GetInstances(serviceName
string) []registry.Serv
Healthy: ins.Healthy,
Metadata: metadata,
GroupName: n.group,
+ Tag: tag,
})
}
return res