← ClaudeAtlas

etcd-golisted

Go etcd 专家 - KV 存储、Watch 监听、分布式锁、租约管理、选主、事务、配置中心。适用:服务发现与注册、分布式配置中心、分布式锁与协调、选主(leader election)、少量关键元��据存储。不适用:大量数据存储(etcd 上限约 8GB)、高频写入场景(Raft 共识写入延迟高)、缓存场景(应使用 Redis)。触发词:etcd, distributed lock, leader election, watch, lease, service discovery, 分布式锁, 选主, 配置中心, 服务发现, KV
omeyang/Thoth · ★ 0 · AI & Automation · score 73
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