From d18837e297753a842262b053d6040dcf13d1b358 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Tue, 15 Aug 2023 14:39:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AE=9E=E4=BE=8B=E7=9A=84?= =?UTF-8?q?=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- define.go | 9 +++++++++ init.go | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/define.go b/define.go index 24f73ad..51073d1 100644 --- a/define.go +++ b/define.go @@ -84,3 +84,12 @@ type WrapperClient struct { func (wc *WrapperClient) GetClient() *clientv3.Client { return wc.client } + +// Close 关闭 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 14:38 2023/8/15 +func (wc *WrapperClient) Close() error { + return wc.GetClient().Close() +} diff --git a/init.go b/init.go index 9e9beb4..3d5f5ba 100644 --- a/init.go +++ b/init.go @@ -101,3 +101,21 @@ func (c *client) GetClientWithError(flag string) (*WrapperClient, error) { } return c.table[flag], nil } + +// RemoveClient 删除client连接 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 14:37 2023/8/15 +func (c *client) RemoveClient(flag string) { + c.lock.RLock() + defer c.lock.RUnlock() + if _, exist := c.table[flag]; !exist { + return + } + // 关闭连接 + _ = c.table[flag].Close() + // 清除实例 + delete(c.table, flag) + return +}