@@ -16,6 +16,7 @@ import (
1616// EtcdClient handles all etcd operations for PostgreSQL synchronization
1717type EtcdClient struct {
1818 * clientv3.Client
19+ prefix string
1920}
2021
2122// NewEtcdClient creates a new etcd client with DSN parsing
@@ -34,6 +35,7 @@ func NewEtcdClient(dsn string) (*EtcdClient, error) {
3435
3536 return & EtcdClient {
3637 Client : client ,
38+ prefix : getPrefix (dsn ),
3739 }, nil
3840}
3941
@@ -46,15 +48,15 @@ func (c *EtcdClient) Close() error {
4648}
4749
4850// WatchPrefix sets up a watch for all keys with the given prefix
49- func (c * EtcdClient ) WatchPrefix (ctx context.Context , prefix string , startRevision int64 ) clientv3.WatchChan {
51+ func (c * EtcdClient ) WatchPrefix (ctx context.Context , startRevision int64 ) clientv3.WatchChan {
5052 opts := []clientv3.OpOption {clientv3 .WithPrefix ()}
5153 if startRevision > 0 {
5254 opts = append (opts , clientv3 .WithRev (startRevision + 1 ))
5355 }
5456
55- watchChan := c .Client .Watch (ctx , prefix , opts ... )
57+ watchChan := c .Client .Watch (ctx , c . prefix , opts ... )
5658 logrus .WithFields (logrus.Fields {
57- "prefix" : prefix ,
59+ "prefix" : c . prefix ,
5860 "revision" : startRevision ,
5961 }).Info ("Started etcd watch" )
6062
@@ -173,7 +175,7 @@ func NewEtcdClientWithRetry(ctx context.Context, dsn string) (*EtcdClient, error
173175}
174176
175177// WatchWithRecovery wraps the etcd watch functionality with automatic recovery
176- func (c * EtcdClient ) WatchWithRecovery (ctx context.Context , prefix string , startRevision int64 ) <- chan clientv3.WatchResponse {
178+ func (c * EtcdClient ) WatchWithRecovery (ctx context.Context , startRevision int64 ) <- chan clientv3.WatchResponse {
177179 watchChan := make (chan clientv3.WatchResponse )
178180
179181 go func () {
@@ -187,7 +189,7 @@ func (c *EtcdClient) WatchWithRecovery(ctx context.Context, prefix string, start
187189 return
188190 default :
189191 // Attempt to establish watch
190- innerWatchChan := c .WatchPrefix (ctx , prefix , currentRevision )
192+ innerWatchChan := c .WatchPrefix (ctx , currentRevision )
191193
192194 for {
193195 select {
@@ -249,7 +251,7 @@ func RetryEtcdOperation(ctx context.Context, operation func() error, operationNa
249251// parseEtcdDSN parses etcd DSN format: etcd://[user:password@]host1:port1[,host2:port2]/[prefix]?param=value
250252func parseEtcdDSN (dsn string ) (* clientv3.Config , error ) {
251253 if dsn == "" {
252- return nil , fmt . Errorf ( "etcd DSN is required" )
254+ return & clientv3. Config {}, nil // Default config
253255 }
254256
255257 // Parse the DSN if provided
@@ -321,8 +323,8 @@ func parseEtcdDSN(dsn string) (*clientv3.Config, error) {
321323 return config , nil
322324}
323325
324- // GetPrefix extracts the prefix from the etcd DSN path
325- func GetPrefix (dsn string ) string {
326+ // getPrefix extracts the prefix from the etcd DSN path
327+ func getPrefix (dsn string ) string {
326328 if dsn == "" || ! strings .HasPrefix (dsn , "etcd://" ) {
327329 return "/"
328330 }
0 commit comments