This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch refactor-with-go
in repository https://gitbox.apache.org/repos/asf/dubbo-admin.git
The following commit(s) were added to refs/heads/refactor-with-go by this push:
new c2647ce4 [ISSUE #998] feat: add governance_config to adapt
configuration center (#1007)
c2647ce4 is described below
commit c2647ce43d41c4aa42c678715a7da0151c1b3533
Author: Yixiang Zhao <[email protected]>
AuthorDate: Mon Mar 6 16:43:41 2023 +0800
[ISSUE #998] feat: add governance_config to adapt configuration center
(#1007)
---
pkg/admin/config/config.go | 4 +++
pkg/admin/config/governance_config.go | 56 +++++++++++++++++++++++++++++++++++
pkg/admin/constant/const.go | 1 +
3 files changed, 61 insertions(+)
diff --git a/pkg/admin/config/config.go b/pkg/admin/config/config.go
index 25f1a2ea..a19b43c8 100644
--- a/pkg/admin/config/config.go
+++ b/pkg/admin/config/config.go
@@ -51,6 +51,8 @@ var (
ConfigCenter config_center.DynamicConfiguration
RegistryCenter registry.Registry
MetadataReportCenter report.MetadataReport
+
+ Group string
)
func LoadConfig() {
@@ -78,6 +80,7 @@ func LoadConfig() {
panic(err)
}
ConfigCenter, err = factory.GetDynamicConfiguration(url)
+ Group = url.GetParam(constant.GroupKey, constant.DefaultGroup)
if err != nil {
log.Print("No configuration found in config center.")
}
@@ -113,6 +116,7 @@ func LoadConfig() {
if err != nil {
panic(err)
}
+ Group = url.GetParam(constant.GroupKey, constant.DefaultGroup)
}
if len(registryAddress) > 0 {
c := newAddressConfig(registryAddress)
diff --git a/pkg/admin/config/governance_config.go
b/pkg/admin/config/governance_config.go
new file mode 100644
index 00000000..bdab60a8
--- /dev/null
+++ b/pkg/admin/config/governance_config.go
@@ -0,0 +1,56 @@
+/*
+ * 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 config
+
+import (
+ "dubbo.apache.org/dubbo-go/v3/config_center"
+ "errors"
+)
+
+func SetConfig(key string, value string) error {
+ return SetConfigWithGroup(Group, key, value)
+}
+
+func GetConfig(key string) (string, error) {
+ return GetConfigWithGroup(Group, key)
+}
+
+func DeleteConfig(key string) error {
+ return DeleteConfigWithGroup(Group, key)
+}
+
+func SetConfigWithGroup(group string, key string, value string) error {
+ if key == "" || value == "" {
+ return errors.New("key or value is empty")
+ }
+ return ConfigCenter.PublishConfig(key, group, value)
+}
+
+func GetConfigWithGroup(group string, key string) (string, error) {
+ if key == "" {
+ return "", errors.New("key is empty")
+ }
+ return ConfigCenter.GetProperties(key, config_center.WithGroup(group))
+}
+
+func DeleteConfigWithGroup(group string, key string) error {
+ if key == "" {
+ return errors.New("key is empty")
+ }
+ return ConfigCenter.RemoveConfig(key, group)
+}
diff --git a/pkg/admin/constant/const.go b/pkg/admin/constant/const.go
index 23f2658f..064045ed 100644
--- a/pkg/admin/constant/const.go
+++ b/pkg/admin/constant/const.go
@@ -42,6 +42,7 @@ const (
ProviderSide = "provider"
ConsumerProtocol = "consumer"
EmptyProtocol = "empty"
+ DefaultGroup = "dubbo"
ApplicationKey = "application"
DynamicKey = "dynamic"
SerializationKey = "serialization"