All!
I've the code below:
package main
import (
"log"
"github.com/coreos/go-etcd/etcd"
)
func main() {
client := etcd.NewClient(
[]string{
"http://172.20.20.10:2379",
"http://172.20.20.11:2379",
"http://172.20.20.12:2379",
},
)
for {
watchChan := make(chan *etcd.Response)
go client.Watch("/config", 0, false, watchChan, nil)
log.Println("Waiting for an update...")
r := <-watchChan
log.Printf(">>> got an updated config: %s: %s
", r.Node.Key, r.Node.Value)
}
}
BUT... When some node (for example 172.20.20.11) is going down the panic is complain regarding the invalid memory address or nil pointer dereference...
> $ ./etcd-watcher
2015/11/09 18:46:19 Waiting for an update...
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x10 pc=0x22fe]
goroutine 1 [running]:
main.main()
/Users/Stalker/Workspace/src/snippets/etcd-watcher.go:26 +0x2be
goroutine 17 [syscall, locked to thread]:
runtime.goexit()
/Users/Stalker/App/Go/1.5.1/src/runtime/asm_amd64.s:1696 +0x1
goroutine 19 [runnable]:
net/http.(*persistConn).writeLoop(0xc8200c6dc0)
/Users/Stalker/App/Go/1.5.1/src/net/http/transport.go:1009 +0x40c
created by net/http.(*Transport).dialConn
/Users/Stalker/App/Go/1.5.1/src/net/http/transport.go:686 +0xc9d
Could someone explain me what is going on and how to make this simple example to work properly?? Thanks a lot for advice! Alex