Skip to content

Commit 39ced1a

Browse files
authored
feat: support password for auth and security (#17)
1 parent 286399c commit 39ced1a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

watcher.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type Watcher struct {
3535
running bool
3636
callback func(string)
3737
keyName string
38+
password string
3839
}
3940

4041
// finalizer is the destructor for Watcher.
@@ -44,12 +45,15 @@ func finalizer(w *Watcher) {
4445

4546
// NewWatcher is the constructor for Watcher.
4647
// endpoints is the endpoints for etcd clusters.
47-
func NewWatcher(endpoints []string, keyName string) (persist.Watcher, error) {
48+
func NewWatcher(endpoints []string, keyName string, password ...string) (persist.Watcher, error) {
4849
w := &Watcher{}
4950
w.endpoints = endpoints
5051
w.running = true
5152
w.callback = nil
5253
w.keyName = keyName
54+
if len(password) > 0 {
55+
w.password = password[0]
56+
}
5357

5458
// Create the client.
5559
err := w.createClient()
@@ -78,6 +82,7 @@ func (w *Watcher) createClient() error {
7882
// set timeout per request to fail fast when the target endpoints is unavailable
7983
DialKeepAliveTimeout: time.Second * 10,
8084
DialTimeout: time.Second * 30,
85+
Password: w.password,
8186
}
8287

8388
c, err := client.New(cfg)

0 commit comments

Comments
 (0)