This is an automated email from the ASF dual-hosted git repository.
ruinova 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 f90420170 feat: inject dubbo.tag into service metadata (#3069)
f90420170 is described below
commit f90420170878066f97ea04fedbc58c56376931b8
Author: zbchi <[email protected]>
AuthorDate: Sun Nov 9 21:03:01 2025 +0800
feat: inject dubbo.tag into service metadata (#3069)
* feat: inject dubbo.tag into service metadata
* Update service_instance_tag_customizer.go
Co-authored-by: Xuetao Li <[email protected]>
---
.../customizer/service_instance_tag_customizer.go | 44 ++++++++++++++++++++
.../service_instance_tag_customizer_test.go | 48 ++++++++++++++++++++++
2 files changed, 92 insertions(+)
diff --git
a/registry/servicediscovery/customizer/service_instance_tag_customizer.go
b/registry/servicediscovery/customizer/service_instance_tag_customizer.go
new file mode 100644
index 000000000..d6bdf728c
--- /dev/null
+++ b/registry/servicediscovery/customizer/service_instance_tag_customizer.go
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package customizer
+
+import (
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+ "dubbo.apache.org/dubbo-go/v3/common/extension"
+ "dubbo.apache.org/dubbo-go/v3/registry"
+)
+
+func init() {
+ extension.AddCustomizers(&tagCustomizer{})
+}
+
+type tagCustomizer struct{}
+
+// GetPriority will return 2 so that it will be invoked in front of user
defining Customizer
+func (t *tagCustomizer) GetPriority() int {
+ return 2
+}
+
+// Customize injects the tag value into instance metadata
+func (t *tagCustomizer) Customize(instance registry.ServiceInstance) {
+ tag := instance.GetTag()
+ if tag == "" {
+ return
+ }
+ instance.GetMetadata()[constant.Tagkey] = tag
+}
diff --git
a/registry/servicediscovery/customizer/service_instance_tag_customizer_test.go
b/registry/servicediscovery/customizer/service_instance_tag_customizer_test.go
new file mode 100644
index 000000000..754b28234
--- /dev/null
+++
b/registry/servicediscovery/customizer/service_instance_tag_customizer_test.go
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package customizer
+
+import (
+ "testing"
+)
+
+import (
+ "github.com/stretchr/testify/assert"
+)
+
+import (
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+ "dubbo.apache.org/dubbo-go/v3/registry"
+)
+
+func TestTagCustomizer(t *testing.T) {
+ tc := &tagCustomizer{}
+ assert.Equal(t, 2, tc.GetPriority())
+
+ instance := createTagInstance()
+ tc.Customize(instance)
+
+ meta := instance.GetMetadata()
+ assert.Equal(t, "gray", meta[constant.Tagkey])
+}
+
+func createTagInstance() registry.ServiceInstance {
+ return ®istry.DefaultServiceInstance{
+ Tag: "gray",
+ }
+}