增加实例的删除

This commit is contained in:
白茶清欢 2023-08-15 14:39:35 +08:00
parent f98497fc0d
commit d18837e297
2 changed files with 27 additions and 0 deletions

View File

@ -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()
}

18
init.go
View File

@ -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
}