etcd-golisted
Install: claude install-skill omeyang/Thoth
# Go etcd 专家
使用 Go etcd client 开发分布式协调功能:$ARGUMENTS
---
## 1. 客户端管理
### 配置与创建
```go
type Config struct {
Endpoints []string // 必需: ["host1:2379", "host2:2379"]
Username string // 可选: 认证用户名
Password string // 可选: 认证密码
DialTimeout time.Duration // 默认: 5s
DialKeepAliveTime time.Duration // 默认: 10s
DialKeepAliveTimeout time.Duration // 默认: 3s
AutoSyncInterval time.Duration // 默认: 0(禁用)
RejectOldCluster bool // 默认: true(安全默认)
PermitWithoutStream bool // 默认: true(保活)
}
func DefaultConfig() *Config
func (c *Config) Validate() error // 校验 host:port 格式(支持 IPv4/IPv6/域名)
```
### 客户端结构
```go
type Client struct {
client etcdClient // 接口,支持 mock 测试
rawClient *clientv3.Client // 高级操作时直接使用
config *Config
closed atomic.Bool
}
func NewClient(config *Config, opts ...Option) (*Client, error)
func (c *Client) RawClient() *clientv3.Client // 获取底层客户端
func (c *Client) Close() error
// 选项
WithContext(ctx context.Context) Option
WithHealthCheck(enabled bool, timeout time.Duration) Option
WithTLS(config *tls.Config) Option
```
---
## 2. KV 操作
### 基本 CRUD
```go
func (c *Client) Get(ctx context.Context, key string) ([]byte, error)
func (c *Client) GetWithRevision(ctx context.Context, key string) ([]byte, int64, error)
func (c *Client) Put(ctx context.Context, key string, value []byte) error
func (c *Client) PutWithTTL(ctx context.C