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 55f774200 Remove the config package from server package (#3207)
55f774200 is described below
commit 55f77420013556d658014848250024f86510db3f
Author: nanjiek <[email protected]>
AuthorDate: Sun Mar 1 23:52:30 2026 +0800
Remove the config package from server package (#3207)
---
.../config/config_post_processor.go | 25 +-
common/extension/config_post_processor.go | 12 +-
internal/config.go | 163 +++++++++++
internal/config_test.go | 256 ++++++++++++++++
internal/internal.go | 4 +-
server/action.go | 6 +-
server/action_test.go | 17 +-
server/compat.go | 63 ----
server/compat_test.go | 324 ---------------------
server/options.go | 38 +--
server/options_test.go | 10 -
11 files changed, 451 insertions(+), 467 deletions(-)
diff --git a/internal/internal.go b/common/config/config_post_processor.go
similarity index 52%
copy from internal/internal.go
copy to common/config/config_post_processor.go
index 983a28ddb..6bc92882b 100644
--- a/internal/internal.go
+++ b/common/config/config_post_processor.go
@@ -15,21 +15,18 @@
* limitations under the License.
*/
-// Package internal contains dubbo-go-internal code, to avoid polluting
-// the top-level dubbo-go package. It must not import any dubbo-go symbols
-// except internal symbols to avoid circular dependencies.
-package internal
+package config
import (
- "dubbo.apache.org/dubbo-go/v3/internal/reflection"
+ "dubbo.apache.org/dubbo-go/v3/common"
)
-var (
- // HealthSetServingStatusServing is used to set service serving status
- // the initialization place is in
/protocol/triple/health/healthServer.go
- HealthSetServingStatusServing = func(service string) {}
- // ReflectionRegister is used to register reflection service provider
- // the initialization place is in
/protocol/triple/reflection/serverreflection.go
- ReflectionRegister = func(reflection reflection.ServiceInfoProvider) {}
- // todo: add metadata func
-)
+// ConfigPostProcessor is an extension to give users a chance to customize
configs against ReferenceConfig and
+// ServiceConfig during deployment time.
+type ConfigPostProcessor interface {
+ // PostProcessReferenceConfig customizes ReferenceConfig's params.
+ PostProcessReferenceConfig(*common.URL)
+
+ // PostProcessServiceConfig customizes ServiceConfig's params.
+ PostProcessServiceConfig(*common.URL)
+}
diff --git a/common/extension/config_post_processor.go
b/common/extension/config_post_processor.go
index 3c3e28530..81df3fa28 100644
--- a/common/extension/config_post_processor.go
+++ b/common/extension/config_post_processor.go
@@ -18,24 +18,24 @@
package extension
import (
- "dubbo.apache.org/dubbo-go/v3/config/interfaces"
+ "dubbo.apache.org/dubbo-go/v3/common/config"
)
-var processors = make(map[string]interfaces.ConfigPostProcessor)
+var processors = make(map[string]config.ConfigPostProcessor)
// SetConfigPostProcessor registers a ConfigPostProcessor with the given name.
-func SetConfigPostProcessor(name string, processor
interfaces.ConfigPostProcessor) {
+func SetConfigPostProcessor(name string, processor config.ConfigPostProcessor)
{
processors[name] = processor
}
// GetConfigPostProcessor finds a ConfigPostProcessor by name.
-func GetConfigPostProcessor(name string) interfaces.ConfigPostProcessor {
+func GetConfigPostProcessor(name string) config.ConfigPostProcessor {
return processors[name]
}
// GetConfigPostProcessors returns all registered instances of
ConfigPostProcessor.
-func GetConfigPostProcessors() []interfaces.ConfigPostProcessor {
- ret := make([]interfaces.ConfigPostProcessor, 0, len(processors))
+func GetConfigPostProcessors() []config.ConfigPostProcessor {
+ ret := make([]config.ConfigPostProcessor, 0, len(processors))
for _, v := range processors {
ret = append(ret, v)
}
diff --git a/internal/config.go b/internal/config.go
new file mode 100644
index 000000000..90ae62fff
--- /dev/null
+++ b/internal/config.go
@@ -0,0 +1,163 @@
+/*
+ * 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 internal contains dubbo-go-internal code, to avoid polluting
+// the top-level dubbo-go package. It must not import any dubbo-go symbols
+// except internal symbols to avoid circular dependencies.
+package internal
+
+import (
+ "net/url"
+ "strconv"
+ "strings"
+)
+
+import (
+ "github.com/dubbogo/gost/log/logger"
+)
+
+import (
+ "dubbo.apache.org/dubbo-go/v3/common"
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+ "dubbo.apache.org/dubbo-go/v3/global"
+)
+
+func LoadRegistries(registryIds []string, registries
map[string]*global.RegistryConfig, roleType common.RoleType) []*common.URL {
+ var registryURLs []*common.URL
+
+ for k, registryConf := range registries {
+ target := false
+
+ if len(registryIds) == 0 || (len(registryIds) == 1 &&
registryIds[0] == "") {
+ target = true
+ } else {
+ for _, tr := range registryIds {
+ if tr == k {
+ target = true
+ break
+ }
+ }
+ }
+
+ if target {
+ urls, err := toURLs(registryConf, roleType)
+ if err != nil {
+ logger.Errorf("The registry id: %s url is
invalid, error: %#v", k, err)
+ continue
+ }
+
+ for _, u := range urls {
+ if u == nil {
+ continue
+ }
+
+ clonedURL := u.Clone()
+ clonedURL.AddParam(constant.RegistryIdKey, k)
+ registryURLs = append(registryURLs, clonedURL)
+ }
+ }
+ }
+
+ return registryURLs
+}
+
+func toURLs(registriesConfig *global.RegistryConfig, roleType common.RoleType)
([]*common.URL, error) {
+ address, err := translateRegistryAddress(registriesConfig)
+ if err != nil {
+ return nil, err
+ }
+ var urls []*common.URL
+ var registryURL *common.URL
+
+ if address == "" || address == constant.NotAvailable {
+ logger.Infof("Empty or N/A registry address found, the process
will work with no registry enabled " +
+ "which means that the address of this instance will not
be registered and not able to be found by other consumer instances.")
+ return urls, nil
+ }
+ switch registriesConfig.RegistryType {
+ case constant.RegistryTypeService:
+ // service discovery protocol
+ if registryURL, err = createNewURL(registriesConfig,
constant.ServiceRegistryProtocol, address, roleType); err == nil {
+ urls = append(urls, registryURL)
+ }
+ case constant.RegistryTypeInterface:
+ if registryURL, err = createNewURL(registriesConfig,
constant.RegistryProtocol, address, roleType); err == nil {
+ urls = append(urls, registryURL)
+ }
+ case constant.RegistryTypeAll:
+ if registryURL, err = createNewURL(registriesConfig,
constant.ServiceRegistryProtocol, address, roleType); err == nil {
+ urls = append(urls, registryURL)
+ }
+ if registryURL, err = createNewURL(registriesConfig,
constant.RegistryProtocol, address, roleType); err == nil {
+ urls = append(urls, registryURL)
+ }
+ default:
+ if registryURL, err = createNewURL(registriesConfig,
constant.ServiceRegistryProtocol, address, roleType); err == nil {
+ urls = append(urls, registryURL)
+ }
+ }
+ return urls, err
+}
+
+func createNewURL(registriesConfig *global.RegistryConfig, protocol string,
address string, roleType common.RoleType) (*common.URL, error) {
+ return common.NewURL(protocol+"://"+address,
+ common.WithParams(getUrlMap(registriesConfig, roleType)),
+ common.WithParamsValue(constant.RegistrySimplifiedKey,
strconv.FormatBool(registriesConfig.Simplified)),
+ common.WithParamsValue(constant.RegistryKey,
registriesConfig.Protocol),
+ common.WithParamsValue(constant.RegistryNamespaceKey,
registriesConfig.Namespace),
+ common.WithParamsValue(constant.RegistryTimeoutKey,
registriesConfig.Timeout),
+ common.WithUsername(registriesConfig.Username),
+ common.WithPassword(registriesConfig.Password),
+ common.WithLocation(registriesConfig.Address),
+ )
+}
+
+func translateRegistryAddress(registriesConfig *global.RegistryConfig)
(string, error) {
+ addr := registriesConfig.Address
+ if strings.Contains(addr, "://") {
+ u, err := url.Parse(addr)
+ if err != nil {
+ return "", err
+ }
+ return u.Host + u.Path, nil
+ }
+ return addr, nil
+}
+
+func getUrlMap(registriesConfig *global.RegistryConfig, roleType
common.RoleType) url.Values {
+ urlMap := url.Values{}
+ urlMap.Set(constant.RegistryGroupKey, registriesConfig.Group)
+ urlMap.Set(constant.RegistryRoleKey, strconv.Itoa(int(roleType)))
+ urlMap.Set(constant.RegistryKey, registriesConfig.Protocol)
+ urlMap.Set(constant.RegistryTimeoutKey, registriesConfig.Timeout)
+ urlMap.Set(constant.RegistryKey+"."+constant.RegistryLabelKey,
strconv.FormatBool(true))
+ urlMap.Set(constant.RegistryKey+"."+constant.PreferredKey,
strconv.FormatBool(registriesConfig.Preferred))
+ urlMap.Set(constant.RegistryKey+"."+constant.RegistryZoneKey,
registriesConfig.Zone)
+ urlMap.Set(constant.RegistryKey+"."+constant.WeightKey,
strconv.FormatInt(registriesConfig.Weight, 10))
+ urlMap.Set(constant.RegistryTTLKey, registriesConfig.TTL)
+ urlMap.Set(constant.ClientNameKey,
clientNameID(registriesConfig.Protocol, registriesConfig.Address))
+ urlMap.Set(constant.RegistryTypeKey, registriesConfig.RegistryType)
+
+ for k, v := range registriesConfig.Params {
+ urlMap.Set(k, v)
+ }
+ return urlMap
+}
+
+func clientNameID(protocol, address string) string {
+ return strings.Join([]string{constant.RegistryConfigPrefix, protocol,
address}, "-")
+}
diff --git a/internal/config_test.go b/internal/config_test.go
new file mode 100644
index 000000000..515786ebf
--- /dev/null
+++ b/internal/config_test.go
@@ -0,0 +1,256 @@
+/*
+ * 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 internal
+
+import (
+ "strconv"
+ "testing"
+)
+
+import (
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+import (
+ "dubbo.apache.org/dubbo-go/v3/common"
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+ "dubbo.apache.org/dubbo-go/v3/global"
+)
+
+func TestLoadRegistries_AllOrEmptyIDs(t *testing.T) {
+ registries := map[string]*global.RegistryConfig{
+ "r1": {
+ Protocol: "mock",
+ Timeout: "2s",
+ Group: "g1",
+ Address: "127.0.0.1:2181",
+ RegistryType: constant.RegistryTypeInterface,
+ },
+ "r2": {
+ Protocol: "mock",
+ Timeout: "2s",
+ Group: "g2",
+ Address: "127.0.0.2:2181",
+ RegistryType: constant.RegistryTypeAll,
+ },
+ }
+
+ tests := []struct {
+ name string
+ ids []string
+ }{
+ {name: "nil", ids: nil},
+ {name: "empty-string", ids: []string{""}},
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ urls := LoadRegistries(tt.ids, registries,
common.CONSUMER)
+ require.Len(t, urls, 3)
+
+ counts := map[string]int{}
+ for _, u := range urls {
+ id := u.GetParam(constant.RegistryIdKey, "")
+ require.NotEmpty(t, id)
+ counts[id]++
+ }
+ assert.Equal(t, 1, counts["r1"])
+ assert.Equal(t, 2, counts["r2"])
+ })
+ }
+}
+
+func TestLoadRegistries_FilteredIDs(t *testing.T) {
+ registries := map[string]*global.RegistryConfig{
+ "r1": {
+ Protocol: "mock",
+ Timeout: "2s",
+ Group: "g1",
+ Address: "127.0.0.1:2181",
+ },
+ "r2": {
+ Protocol: "mock",
+ Timeout: "2s",
+ Group: "g2",
+ Address: "127.0.0.2:2181",
+ },
+ }
+
+ urls := LoadRegistries([]string{"r1"}, registries, common.CONSUMER)
+ require.Len(t, urls, 1)
+ for _, u := range urls {
+ assert.Equal(t, "r1", u.GetParam(constant.RegistryIdKey, ""))
+ }
+}
+
+func TestLoadRegistries_SkipInvalidURL(t *testing.T) {
+ registries := map[string]*global.RegistryConfig{
+ "bad": {
+ Protocol: "mock",
+ Timeout: "2s",
+ Group: "g1",
+ Address: "127.0.0.1:bad",
+ },
+ }
+
+ urls := LoadRegistries([]string{"bad"}, registries, common.CONSUMER)
+ assert.Empty(t, urls)
+}
+
+func TestToURLs_EmptyOrNA(t *testing.T) {
+ tests := []struct {
+ name string
+ address string
+ }{
+ {name: "empty", address: ""},
+ {name: "na", address: constant.NotAvailable},
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ cfg := &global.RegistryConfig{
+ Protocol: "mock",
+ Address: tt.address,
+ }
+ urls, err := toURLs(cfg, common.CONSUMER)
+ require.NoError(t, err)
+ assert.Empty(t, urls)
+ })
+ }
+}
+
+func TestToURLs_RegistryTypeAll(t *testing.T) {
+ cfg := &global.RegistryConfig{
+ Protocol: "mock",
+ Address: "127.0.0.1:2181",
+ RegistryType: constant.RegistryTypeAll,
+ }
+
+ urls, err := toURLs(cfg, common.CONSUMER)
+ require.NoError(t, err)
+ require.Len(t, urls, 2)
+
+ protocols := map[string]bool{}
+ for _, u := range urls {
+ protocols[u.Protocol] = true
+ assert.Equal(t, "127.0.0.1:2181", u.Location)
+ }
+ assert.True(t, protocols[constant.ServiceRegistryProtocol])
+ assert.True(t, protocols[constant.RegistryProtocol])
+}
+
+func TestTranslateRegistryAddress(t *testing.T) {
+ tests := []struct {
+ name string
+ address string
+ want string
+ }{
+ {name: "simple", address: "nacos://127.0.0.1:8848", want:
"127.0.0.1:8848"},
+ {name: "path", address: "nacos://127.0.0.1:8848/path", want:
"127.0.0.1:8848/path"},
+ {name: "invalid", address: "://bad", want: "://bad"},
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ cfg := &global.RegistryConfig{Address: tt.address}
+ got, err := translateRegistryAddress(cfg)
+ if tt.name == "invalid" {
+ require.Error(t, err)
+ return
+ }
+ require.NoError(t, err)
+ assert.Equal(t, tt.want, got)
+ })
+ }
+}
+
+func TestGetUrlMap_BasicAndOverrides(t *testing.T) {
+ cfg := &global.RegistryConfig{
+ Protocol: "mock",
+ Timeout: "5s",
+ Group: "group",
+ TTL: "15m",
+ Address: "127.0.0.1:2181",
+ Preferred: true,
+ Zone: "zone",
+ Weight: 200,
+ RegistryType: constant.RegistryTypeInterface,
+ Params: map[string]string{
+ "custom": "x",
+ constant.RegistryTimeoutKey: "override",
+ },
+ }
+
+ values := getUrlMap(cfg, common.PROVIDER)
+ assert.Equal(t, "group", values.Get(constant.RegistryGroupKey))
+ assert.Equal(t, strconv.Itoa(int(common.PROVIDER)),
values.Get(constant.RegistryRoleKey))
+ assert.Equal(t, "mock", values.Get(constant.RegistryKey))
+ assert.Equal(t, "override", values.Get(constant.RegistryTimeoutKey))
+ assert.Equal(t, "true",
values.Get(constant.RegistryKey+"."+constant.RegistryLabelKey))
+ assert.Equal(t, "true",
values.Get(constant.RegistryKey+"."+constant.PreferredKey))
+ assert.Equal(t, "zone",
values.Get(constant.RegistryKey+"."+constant.RegistryZoneKey))
+ assert.Equal(t, "200",
values.Get(constant.RegistryKey+"."+constant.WeightKey))
+ assert.Equal(t, "15m", values.Get(constant.RegistryTTLKey))
+ assert.Equal(t, "x", values.Get("custom"))
+ assert.Equal(t, clientNameID(cfg.Protocol, cfg.Address),
values.Get(constant.ClientNameKey))
+ assert.Equal(t, constant.RegistryTypeInterface,
values.Get(constant.RegistryTypeKey))
+}
+
+func TestCreateNewURL_SetsFields(t *testing.T) {
+ cfg := &global.RegistryConfig{
+ Protocol: "mock",
+ Timeout: "10s",
+ Group: "group",
+ Namespace: "ns",
+ TTL: "15m",
+ Address: "127.0.0.1:2181",
+ Username: "user",
+ Password: "pass",
+ Simplified: true,
+ Preferred: false,
+ Zone: "zone",
+ Weight: 100,
+ RegistryType: constant.RegistryTypeService,
+ Params: map[string]string{
+ "custom": "x",
+ },
+ }
+
+ u, err := createNewURL(cfg, constant.ServiceRegistryProtocol,
cfg.Address, common.CONSUMER)
+ require.NoError(t, err)
+
+ assert.Equal(t, constant.ServiceRegistryProtocol, u.Protocol)
+ assert.Equal(t, cfg.Address, u.Location)
+ assert.Equal(t, cfg.Username, u.Username)
+ assert.Equal(t, cfg.Password, u.Password)
+ assert.Equal(t, "true", u.GetParam(constant.RegistrySimplifiedKey, ""))
+ assert.Equal(t, cfg.Protocol, u.GetParam(constant.RegistryKey, ""))
+ assert.Equal(t, cfg.Namespace,
u.GetParam(constant.RegistryNamespaceKey, ""))
+ assert.Equal(t, cfg.Timeout, u.GetParam(constant.RegistryTimeoutKey,
""))
+ assert.Equal(t, strconv.Itoa(int(common.CONSUMER)),
u.GetParam(constant.RegistryRoleKey, ""))
+ assert.Equal(t, cfg.Group, u.GetParam(constant.RegistryGroupKey, ""))
+ assert.Equal(t, cfg.TTL, u.GetParam(constant.RegistryTTLKey, ""))
+ assert.Equal(t, clientNameID(cfg.Protocol, cfg.Address),
u.GetParam(constant.ClientNameKey, ""))
+ assert.Equal(t, "x", u.GetParam("custom", ""))
+}
+
+func TestClientNameID(t *testing.T) {
+ got := clientNameID("nacos", "127.0.0.1:8848")
+ assert.Equal(t, "dubbo.registries-nacos-127.0.0.1:8848", got)
+}
diff --git a/internal/internal.go b/internal/internal.go
index 983a28ddb..93aafad61 100644
--- a/internal/internal.go
+++ b/internal/internal.go
@@ -16,8 +16,8 @@
*/
// Package internal contains dubbo-go-internal code, to avoid polluting
-// the top-level dubbo-go package. It must not import any dubbo-go symbols
-// except internal symbols to avoid circular dependencies.
+// the top-level dubbo-go package. It should avoid importing packages
+// (such as server/config) that would introduce circular dependencies.
package internal
import (
diff --git a/server/action.go b/server/action.go
index d9942c90b..a90136b20 100644
--- a/server/action.go
+++ b/server/action.go
@@ -40,9 +40,9 @@ import (
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/extension"
- "dubbo.apache.org/dubbo-go/v3/config"
"dubbo.apache.org/dubbo-go/v3/global"
"dubbo.apache.org/dubbo-go/v3/graceful_shutdown"
+ "dubbo.apache.org/dubbo-go/v3/internal"
"dubbo.apache.org/dubbo-go/v3/protocol/base"
"dubbo.apache.org/dubbo-go/v3/protocol/protocolwrapper"
)
@@ -141,7 +141,7 @@ func (svcOpts *ServiceOptions) Export() error {
regUrls := make([]*common.URL, 0)
if !svcConf.NotRegister {
- regUrls = config.LoadRegistries(svcConf.RegistryIDs,
svcOpts.registriesCompat, common.PROVIDER)
+ regUrls = internal.LoadRegistries(svcConf.RegistryIDs,
svcOpts.Registries, common.PROVIDER)
}
urlMap := svcOpts.getUrlMap()
@@ -327,7 +327,7 @@ func (svcOpts *ServiceOptions) Implement(rpcService
common.RPCService) {
func (svcOpts *ServiceOptions) getUrlMap() url.Values {
svcConf := svcOpts.Service
- app := svcOpts.applicationCompat
+ app := svcOpts.Application
metrics := svcOpts.srvOpts.Metrics
tracing := svcOpts.srvOpts.Otel.TracingConfig
diff --git a/server/action_test.go b/server/action_test.go
index 24014b0b4..dcb0331bb 100644
--- a/server/action_test.go
+++ b/server/action_test.go
@@ -30,7 +30,6 @@ import (
import (
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/common/constant"
- "dubbo.apache.org/dubbo-go/v3/config"
"dubbo.apache.org/dubbo-go/v3/global"
"dubbo.apache.org/dubbo-go/v3/protocol/base"
)
@@ -302,7 +301,7 @@ func TestGetUrlMapBasic(t *testing.T) {
Version: "1.0.0",
},
Provider: &global.ProviderConfig{},
- applicationCompat: &config.ApplicationConfig{
+ Application: &global.ApplicationConfig{
Name: "test-app",
Organization: "test-org",
Module: "test-module",
@@ -343,7 +342,7 @@ func TestGetUrlMapWithParams(t *testing.T) {
Serialization: constant.JSONSerialization,
},
Provider: &global.ProviderConfig{},
- applicationCompat: &config.ApplicationConfig{
+ Application: &global.ApplicationConfig{
Name: "test-app",
Organization: "test-org",
},
@@ -375,7 +374,7 @@ func TestGetUrlMapWithGroupAndVersion(t *testing.T) {
Params: map[string]string{},
},
Provider: &global.ProviderConfig{},
- applicationCompat: &config.ApplicationConfig{
+ Application: &global.ApplicationConfig{
Name: "test-app",
},
srvOpts: &ServerOptions{
@@ -412,7 +411,7 @@ func TestGetUrlMapWithMethods(t *testing.T) {
},
},
Provider: &global.ProviderConfig{},
- applicationCompat: &config.ApplicationConfig{
+ Application: &global.ApplicationConfig{
Name: "test-app",
},
srvOpts: &ServerOptions{
@@ -545,7 +544,7 @@ func TestGetUrlMapWithTpsLimit(t *testing.T) {
Params: map[string]string{},
},
Provider: &global.ProviderConfig{},
- applicationCompat: &config.ApplicationConfig{
+ Application: &global.ApplicationConfig{
Name: "test-app",
},
srvOpts: &ServerOptions{
@@ -578,7 +577,7 @@ func TestGetUrlMapWithExecuteLimit(t *testing.T) {
Params: map[string]string{},
},
Provider: &global.ProviderConfig{},
- applicationCompat: &config.ApplicationConfig{
+ Application: &global.ApplicationConfig{
Name: "test-app",
},
srvOpts: &ServerOptions{
@@ -609,7 +608,7 @@ func TestGetUrlMapWithAuthAndParamSign(t *testing.T) {
Params: map[string]string{},
},
Provider: &global.ProviderConfig{},
- applicationCompat: &config.ApplicationConfig{
+ Application: &global.ApplicationConfig{
Name: "test-app",
},
srvOpts: &ServerOptions{
@@ -639,7 +638,7 @@ func TestGetUrlMapWithAccessLog(t *testing.T) {
Params: map[string]string{},
},
Provider: &global.ProviderConfig{},
- applicationCompat: &config.ApplicationConfig{
+ Application: &global.ApplicationConfig{
Name: "test-app",
},
srvOpts: &ServerOptions{
diff --git a/server/compat.go b/server/compat.go
deleted file mode 100644
index 584aa1443..000000000
--- a/server/compat.go
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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 server
-
-import (
- "dubbo.apache.org/dubbo-go/v3/config"
- "dubbo.apache.org/dubbo-go/v3/global"
-)
-
-// these functions are used to resolve circular dependencies temporarily.
-// please refer to issue(https://github.com/apache/dubbo-go/issues/2377)
-// todo(DMwangnima): remove these functions when refactoring dubbo-go
-func compatApplicationConfig(c *global.ApplicationConfig)
*config.ApplicationConfig {
- return &config.ApplicationConfig{
- Organization: c.Organization,
- Name: c.Name,
- Module: c.Module,
- Group: c.Group,
- Version: c.Version,
- Owner: c.Owner,
- Environment: c.Environment,
- MetadataType: c.MetadataType,
- Tag: c.Tag,
- MetadataServicePort: c.MetadataServicePort,
- MetadataServiceProtocol: c.MetadataServiceProtocol,
- }
-}
-
-func compatRegistryConfig(c *global.RegistryConfig) *config.RegistryConfig {
- return &config.RegistryConfig{
- Protocol: c.Protocol,
- Timeout: c.Timeout,
- Group: c.Group,
- Namespace: c.Namespace,
- TTL: c.TTL,
- Address: c.Address,
- Username: c.Username,
- Password: c.Password,
- Simplified: c.Simplified,
- Preferred: c.Preferred,
- Zone: c.Zone,
- Weight: c.Weight,
- Params: c.Params,
- RegistryType: c.RegistryType,
- UseAsMetaReport: c.UseAsMetaReport,
- UseAsConfigCenter: c.UseAsConfigCenter,
- }
-}
diff --git a/server/compat_test.go b/server/compat_test.go
deleted file mode 100644
index 7151d0d61..000000000
--- a/server/compat_test.go
+++ /dev/null
@@ -1,324 +0,0 @@
-/*
- * 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 server
-
-import (
- "testing"
-)
-
-import (
- "github.com/stretchr/testify/assert"
-)
-
-import (
- "dubbo.apache.org/dubbo-go/v3/config"
- "dubbo.apache.org/dubbo-go/v3/global"
-)
-
-// Test compatApplicationConfig with all fields
-func TestCompatApplicationConfigAll(t *testing.T) {
- appCfg := &global.ApplicationConfig{
- Organization: "test-org",
- Name: "test-app",
- Module: "test-module",
- Group: "test-group",
- Version: "1.0.0",
- Owner: "test-owner",
- Environment: "test-env",
- MetadataType: "remote",
- Tag: "v1",
- MetadataServicePort: "30880",
- MetadataServiceProtocol: "triple",
- }
-
- result := compatApplicationConfig(appCfg)
-
- assert.NotNil(t, result)
- assert.Equal(t, "test-org", result.Organization)
- assert.Equal(t, "test-app", result.Name)
- assert.Equal(t, "test-module", result.Module)
- assert.Equal(t, "test-group", result.Group)
- assert.Equal(t, "1.0.0", result.Version)
- assert.Equal(t, "test-owner", result.Owner)
- assert.Equal(t, "test-env", result.Environment)
- assert.Equal(t, "remote", result.MetadataType)
- assert.Equal(t, "v1", result.Tag)
- assert.Equal(t, "30880", result.MetadataServicePort)
- assert.Equal(t, "triple", result.MetadataServiceProtocol)
-}
-
-// Test compatApplicationConfig with partial fields
-func TestCompatApplicationConfigPartial(t *testing.T) {
- appCfg := &global.ApplicationConfig{
- Name: "test-app",
- Version: "1.0.0",
- }
-
- result := compatApplicationConfig(appCfg)
-
- assert.NotNil(t, result)
- assert.Equal(t, "test-app", result.Name)
- assert.Equal(t, "1.0.0", result.Version)
- assert.Empty(t, result.Organization)
- assert.Empty(t, result.Module)
-}
-
-// Test compatApplicationConfig with empty config
-func TestCompatApplicationConfigEmpty(t *testing.T) {
- appCfg := &global.ApplicationConfig{}
-
- result := compatApplicationConfig(appCfg)
-
- assert.NotNil(t, result)
- assert.Empty(t, result.Name)
- assert.Empty(t, result.Organization)
- assert.Empty(t, result.Module)
- assert.Empty(t, result.Group)
- assert.Empty(t, result.Version)
- assert.Empty(t, result.Owner)
- assert.Empty(t, result.Environment)
- assert.Empty(t, result.MetadataType)
- assert.Empty(t, result.Tag)
- assert.Empty(t, result.MetadataServicePort)
- assert.Empty(t, result.MetadataServiceProtocol)
-}
-
-// Test compatRegistryConfig with all fields
-func TestCompatRegistryConfigAll(t *testing.T) {
- regCfg := &global.RegistryConfig{
- Protocol: "zookeeper",
- Timeout: "10s",
- Group: "registry-group",
- Namespace: "test-ns",
- TTL: "60s",
- Address: "localhost:2181",
- Username: "admin",
- Password: "password",
- Simplified: true,
- Preferred: true,
- Zone: "zone1",
- Weight: 100,
- Params: map[string]string{"key": "value"},
- RegistryType: "service_discovery",
- UseAsMetaReport: "true",
- UseAsConfigCenter: "true",
- }
-
- result := compatRegistryConfig(regCfg)
-
- assert.NotNil(t, result)
- assert.Equal(t, "zookeeper", result.Protocol)
- assert.Equal(t, "10s", result.Timeout)
- assert.Equal(t, "registry-group", result.Group)
- assert.Equal(t, "test-ns", result.Namespace)
- assert.Equal(t, "60s", result.TTL)
- assert.Equal(t, "localhost:2181", result.Address)
- assert.Equal(t, "admin", result.Username)
- assert.Equal(t, "password", result.Password)
- assert.True(t, result.Simplified)
- assert.True(t, result.Preferred)
- assert.Equal(t, "zone1", result.Zone)
- assert.Equal(t, int64(100), result.Weight)
- assert.Equal(t, "service_discovery", result.RegistryType)
- assert.Equal(t, "true", result.UseAsMetaReport)
- assert.Equal(t, "true", result.UseAsConfigCenter)
- assert.NotNil(t, result.Params)
- assert.Equal(t, "value", result.Params["key"])
-}
-
-// Test compatRegistryConfig with partial fields
-func TestCompatRegistryConfigPartial(t *testing.T) {
- regCfg := &global.RegistryConfig{
- Protocol: "nacos",
- Address: "localhost:8848",
- }
-
- result := compatRegistryConfig(regCfg)
-
- assert.NotNil(t, result)
- assert.Equal(t, "nacos", result.Protocol)
- assert.Equal(t, "localhost:8848", result.Address)
- assert.Empty(t, result.Timeout)
- assert.Empty(t, result.Group)
-}
-
-// Test compatRegistryConfig with empty config
-func TestCompatRegistryConfigEmpty(t *testing.T) {
- regCfg := &global.RegistryConfig{}
-
- result := compatRegistryConfig(regCfg)
-
- assert.NotNil(t, result)
- assert.Empty(t, result.Protocol)
- assert.Empty(t, result.Address)
- assert.Empty(t, result.Timeout)
- assert.Empty(t, result.Group)
- assert.Empty(t, result.Namespace)
- assert.Empty(t, result.TTL)
- assert.Empty(t, result.Username)
- assert.Empty(t, result.Password)
- assert.False(t, result.Simplified)
- assert.False(t, result.Preferred)
-}
-
-// Test compatRegistryConfig with boolean fields
-func TestCompatRegistryConfigBooleans(t *testing.T) {
- regCfg := &global.RegistryConfig{
- Protocol: "etcd",
- Simplified: true,
- Preferred: true,
- UseAsMetaReport: "true",
- UseAsConfigCenter: "false",
- }
-
- result := compatRegistryConfig(regCfg)
-
- assert.NotNil(t, result)
- assert.True(t, result.Simplified)
- assert.True(t, result.Preferred)
- assert.Equal(t, "true", result.UseAsMetaReport)
- assert.Equal(t, "false", result.UseAsConfigCenter)
-}
-
-// Test compatRegistryConfig with numeric fields
-func TestCompatRegistryConfigNumeric(t *testing.T) {
- regCfg := &global.RegistryConfig{
- Protocol: "zookeeper",
- Weight: 500,
- }
-
- result := compatRegistryConfig(regCfg)
-
- assert.NotNil(t, result)
- assert.Equal(t, "zookeeper", result.Protocol)
- assert.Equal(t, int64(500), result.Weight)
-}
-
-// Test compatRegistryConfig with params
-func TestCompatRegistryConfigWithParams(t *testing.T) {
- regCfg := &global.RegistryConfig{
- Protocol: "zookeeper",
- Params: map[string]string{
- "key1": "value1",
- "key2": "value2",
- "key3": "value3",
- },
- }
-
- result := compatRegistryConfig(regCfg)
-
- assert.NotNil(t, result)
- assert.Len(t, result.Params, 3)
- assert.Equal(t, "value1", result.Params["key1"])
- assert.Equal(t, "value2", result.Params["key2"])
- assert.Equal(t, "value3", result.Params["key3"])
-}
-
-// Test compatApplicationConfig preserves all field types
-func TestCompatApplicationConfigFieldPreservation(t *testing.T) {
- appCfg := &global.ApplicationConfig{
- Name: "myapp",
- Organization: "myorg",
- Module: "mymodule",
- Group: "mygroup",
- Version: "2.0.0",
- Owner: "owner",
- Environment: "production",
- MetadataType: "local",
- Tag: "beta",
- MetadataServicePort: "25555",
- MetadataServiceProtocol: "grpc",
- }
-
- result := compatApplicationConfig(appCfg)
-
- // Verify type conversion doesn't lose data
- assert.IsType(t, (*config.ApplicationConfig)(nil), result)
- assert.Equal(t, appCfg.Name, result.Name)
- assert.Equal(t, appCfg.Organization, result.Organization)
- assert.Equal(t, appCfg.Module, result.Module)
-}
-
-// Test compatRegistryConfig preserves all field types
-func TestCompatRegistryConfigFieldPreservation(t *testing.T) {
- regCfg := &global.RegistryConfig{
- Protocol: "consul",
- Timeout: "30s",
- Group: "consul-group",
- Namespace: "consul-ns",
- TTL: "120s",
- Address: "localhost:8500",
- Username: "consul-user",
- Password: "consul-pass",
- Simplified: true,
- Preferred: false,
- Zone: "zone-a",
- Weight: 200,
- Params: map[string]string{"consul-key":
"consul-val"},
- RegistryType: "interface",
- UseAsMetaReport: "true",
- UseAsConfigCenter: "false",
- }
-
- result := compatRegistryConfig(regCfg)
-
- // Verify type conversion doesn't lose data
- assert.IsType(t, (*config.RegistryConfig)(nil), result)
- assert.Equal(t, regCfg.Protocol, result.Protocol)
- assert.Equal(t, regCfg.Timeout, result.Timeout)
- assert.Equal(t, regCfg.Group, result.Group)
-}
-
-// Test multiple conversions don't affect original
-func TestCompatConfigsPreservesOriginal(t *testing.T) {
- appCfg := &global.ApplicationConfig{
- Name: "original-app",
- Version: "1.0.0",
- }
-
- result1 := compatApplicationConfig(appCfg)
- result2 := compatApplicationConfig(appCfg)
-
- assert.Equal(t, "original-app", appCfg.Name)
- assert.Equal(t, "1.0.0", appCfg.Version)
-
- assert.Equal(t, result1.Name, result2.Name)
- assert.Equal(t, result1.Version, result2.Version)
- assert.Equal(t, "original-app", result1.Name)
-}
-
-// Test compatRegistryConfig with special characters in params
-func TestCompatRegistryConfigSpecialChars(t *testing.T) {
- regCfg := &global.RegistryConfig{
- Protocol: "zookeeper",
- Params: map[string]string{
- "special.key": "value with spaces",
- "another-key": "value/with/slashes",
- "key_with_colon": "value:with:colons",
- "key.with.dots": "value.with.dots",
- },
- }
-
- result := compatRegistryConfig(regCfg)
-
- assert.NotNil(t, result)
- assert.Equal(t, "value with spaces", result.Params["special.key"])
- assert.Equal(t, "value/with/slashes", result.Params["another-key"])
- assert.Equal(t, "value:with:colons", result.Params["key_with_colon"])
- assert.Equal(t, "value.with.dots", result.Params["key.with.dots"])
-}
diff --git a/server/options.go b/server/options.go
index 3c8413a81..53aea1880 100644
--- a/server/options.go
+++ b/server/options.go
@@ -39,7 +39,6 @@ import (
commonCfg "dubbo.apache.org/dubbo-go/v3/common/config"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/dubboutil"
- "dubbo.apache.org/dubbo-go/v3/config"
aslimiter "dubbo.apache.org/dubbo-go/v3/filter/adaptivesvc/limiter"
"dubbo.apache.org/dubbo-go/v3/global"
"dubbo.apache.org/dubbo-go/v3/graceful_shutdown"
@@ -498,11 +497,7 @@ type ServiceOptions struct {
// for triple non-IDL mode
// consider put here or global.ServiceConfig
// string for url
- // TODO: remove this when config package is remove
IDLMode string
-
- applicationCompat *config.ApplicationConfig
- registriesCompat map[string]*config.RegistryConfig
}
func defaultServiceOptions() *ServiceOptions {
@@ -532,20 +527,11 @@ func (svcOpts *ServiceOptions) init(srv *Server, opts
...ServiceOption) error {
application := svcOpts.Application
if application != nil {
- svcOpts.applicationCompat = compatApplicationConfig(application)
- if err := svcOpts.applicationCompat.Init(); err != nil {
- return err
- }
- // todo(DMwangnima): make this clearer
- // this statement is responsible for setting
rootConfig.Application
- // since many modules would retrieve this information directly.
- config.GetRootConfig().Application = svcOpts.applicationCompat
- svcOpts.metadataType = svcOpts.applicationCompat.MetadataType
if svc.Group == "" {
- svc.Group = svcOpts.applicationCompat.Group
+ svc.Group = application.Group
}
if svc.Version == "" {
- svc.Version = svcOpts.applicationCompat.Version
+ svc.Version = application.Version
}
}
svcOpts.unexported = atomic.NewBool(false)
@@ -554,15 +540,6 @@ func (svcOpts *ServiceOptions) init(srv *Server, opts
...ServiceOption) error {
if len(svc.RCRegistriesMap) == 0 {
svc.RCRegistriesMap = svcOpts.Registries
}
- if len(svc.RCRegistriesMap) > 0 {
- svcOpts.registriesCompat =
make(map[string]*config.RegistryConfig)
- for key, reg := range svc.RCRegistriesMap {
- svcOpts.registriesCompat[key] =
compatRegistryConfig(reg)
- if err := svcOpts.registriesCompat[key].Init(); err !=
nil {
- return err
- }
- }
- }
// initialize Protocols
if len(svc.RCProtocolsMap) == 0 {
@@ -888,17 +865,6 @@ func WithRegistry(opts ...registry.Option) ServiceOption {
}
}
-func WithMethod(opts ...config.MethodOption) ServiceOption {
- regOpts := config.NewMethodOptions(opts...)
-
- return func(opts *ServiceOptions) {
- if len(opts.Service.Methods) == 0 {
- opts.Service.Methods = make([]*global.MethodConfig, 0)
- }
- opts.Service.Methods = append(opts.Service.Methods,
regOpts.Method)
- }
-}
-
func WithParam(k, v string) ServiceOption {
return func(opts *ServiceOptions) {
if opts.Service.Params == nil {
diff --git a/server/options_test.go b/server/options_test.go
index aa511818e..21d440653 100644
--- a/server/options_test.go
+++ b/server/options_test.go
@@ -941,16 +941,6 @@ func TestWithRegistry(t *testing.T) {
assert.Equal(t, "nacos", opts.Registries["test-registry"].Protocol)
}
-// Test WithMethod
-func TestWithMethod(t *testing.T) {
- opts := defaultServiceOptions()
- opt := WithMethod()
- opt(opts)
- assert.NotNil(t, opts.Service.Methods)
- // Verify that a method was actually added
- assert.Len(t, opts.Service.Methods, 1)
-}
-
// Test WithProtocolIDs for ServiceOptions
func TestWithProtocolIDs(t *testing.T) {
opts := defaultServiceOptions()