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 97e163499 fix: Failed to get app metadata for revision cause meta-v is 
wrong (#2952)
97e163499 is described below

commit 97e163499fa4ee098c4081b2e7cefb6788846b98
Author: foghost <[email protected]>
AuthorDate: Wed Jul 16 19:16:35 2025 +0800

    fix: Failed to get app metadata for revision cause meta-v is wrong (#2952)
    
    * fix Failed to get app metadata for revision cause meta-v is wrong
    
    * add some comments
    
    * optimize var name
---
 common/constant/key.go                             |  1 +
 metadata/metadata_service.go                       |  2 +-
 .../metadata_service_version_customizer.go         | 23 +++++++++++++++++++++-
 3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/common/constant/key.go b/common/constant/key.go
index fdc9cc576..da43d9b95 100644
--- a/common/constant/key.go
+++ b/common/constant/key.go
@@ -390,6 +390,7 @@ const (
 
        MetadataServiceV1        = "MetadataServiceV1"
        MetadataServiceV2        = "MetadataServiceV2"
+       MetadataServiceV1Version = "1.0.0"
        MetadataServiceV2Version = "2.0.0"
 )
 
diff --git a/metadata/metadata_service.go b/metadata/metadata_service.go
index d534aed85..9e40ddcb9 100644
--- a/metadata/metadata_service.go
+++ b/metadata/metadata_service.go
@@ -43,7 +43,7 @@ import (
 
 // version will be used by Version func
 const (
-       version  = "1.0.0"
+       version  = constant.MetadataServiceV1Version
        allMatch = "*"
 )
 
diff --git 
a/registry/servicediscovery/customizer/metadata_service_version_customizer.go 
b/registry/servicediscovery/customizer/metadata_service_version_customizer.go
index 3aba022ca..62425e19d 100644
--- 
a/registry/servicediscovery/customizer/metadata_service_version_customizer.go
+++ 
b/registry/servicediscovery/customizer/metadata_service_version_customizer.go
@@ -17,6 +17,14 @@
 
 package customizer
 
+import (
+       "encoding/json"
+)
+
+import (
+       "github.com/dubbogo/gost/log/logger"
+)
+
 import (
        "dubbo.apache.org/dubbo-go/v3/common/constant"
        "dubbo.apache.org/dubbo-go/v3/common/extension"
@@ -38,5 +46,18 @@ func (p *MetadtaServiceVersionCustomizer) GetPriority() int {
 
 // Customize put the the string like [{"protocol": "dubbo", "port": 123}] into 
instance's metadata
 func (p *MetadtaServiceVersionCustomizer) Customize(instance 
registry.ServiceInstance) {
-       instance.GetMetadata()[constant.MetadataVersion] = 
constant.MetadataServiceV2Version
+       metadata := 
instance.GetMetadata()[constant.MetadataServiceURLParamsPropertyName]
+       params := make(map[string]string)
+       err := json.Unmarshal([]byte(metadata), &params)
+       if err != nil {
+               logger.Errorf("json unmarshal error %v", err)
+               return
+       }
+       if (params[constant.ProtocolKey]) == constant.TriProtocol {
+               // triple support v1 and v2, and v2 is preferred to use
+               instance.GetMetadata()[constant.MetadataVersion] = 
constant.MetadataServiceV2Version
+       } else {
+               // dubbo support only v1
+               instance.GetMetadata()[constant.MetadataVersion] = 
constant.MetadataServiceV1Version
+       }
 }

Reply via email to