feat: implement RemoveConfig API for nacos and zookeeper (#2234)
diff --git a/config_center/nacos/impl.go b/config_center/nacos/impl.go
index 1a4ffa8..50209dd 100644
--- a/config_center/nacos/impl.go
+++ b/config_center/nacos/impl.go
@@ -123,6 +123,22 @@
return nil
}
+// RemoveConfig will remove the config with the (key, group) pair
+func (n *nacosDynamicConfiguration) RemoveConfig(key string, group string) error {
+ group = n.resolvedGroup(group)
+ ok, err := n.client.Client().DeleteConfig(vo.ConfigParam{
+ DataId: key,
+ Group: group,
+ })
+ if err != nil {
+ return perrors.WithStack(err)
+ }
+ if !ok {
+ return perrors.New("remove config from Nacos failed")
+ }
+ return nil
+}
+
// GetConfigKeysByGroup will return all keys with the group
func (n *nacosDynamicConfiguration) GetConfigKeysByGroup(group string) (*gxset.HashSet, error) {
group = n.resolvedGroup(group)
diff --git a/config_center/zookeeper/impl.go b/config_center/zookeeper/impl.go
index 538058c..e22f7ad 100644
--- a/config_center/zookeeper/impl.go
+++ b/config_center/zookeeper/impl.go
@@ -171,6 +171,16 @@
return nil
}
+// RemoveConfig will remove the config with the (key, group) pair
+func (c *zookeeperDynamicConfiguration) RemoveConfig(key string, group string) error {
+ path := c.getPath(key, group)
+ err := c.client.Delete(path)
+ if err != nil {
+ return perrors.WithStack(err)
+ }
+ return nil
+}
+
// GetConfigKeysByGroup will return all keys with the group
func (c *zookeeperDynamicConfiguration) GetConfigKeysByGroup(group string) (*gxset.HashSet, error) {
path := c.getPath("", group)