浏览代码

Merge pull request #6896 from gyuho/endpoints

clientv3: return copy of endpoints, not pointer
Gyu-Ho Lee 9 年之前
父节点
当前提交
c31b1ab8d1
共有 1 个文件被更改,包括 6 次插入1 次删除
  1. 6 1
      clientv3/client.go

+ 6 - 1
clientv3/client.go

@@ -97,7 +97,12 @@ func (c *Client) Close() error {
 func (c *Client) Ctx() context.Context { return c.ctx }
 
 // Endpoints lists the registered endpoints for the client.
-func (c *Client) Endpoints() []string { return c.cfg.Endpoints }
+func (c *Client) Endpoints() (eps []string) {
+	// copy the slice; protect original endpoints from being changed
+	eps = make([]string, len(c.cfg.Endpoints))
+	copy(eps, c.cfg.Endpoints)
+	return
+}
 
 // SetEndpoints updates client's endpoints.
 func (c *Client) SetEndpoints(eps ...string) {