Exemplo n.º 1
0
func WatchServices(receiver chan *etcd.Response) {
	client := clients.EtcdClient()

	if client == nil {
		fmt.Println("Error connecting to etcd")
	}

	// Set the directory
	client.SetDir(etcdWatchKey, 0)

	for {
		fmt.Printf("Created etcd watcher: key=%s\n", etcdWatchKey)

		_, err := client.Watch(etcdWatchKey, 0, true, receiver, nil)

		var errString string
		if err == nil {
			errString = "N/A"
		} else {
			errString = err.Error()
		}

		fmt.Printf("etcd watch exited: key=%s, err=\"%s\"\n", etcdWatchKey, errString)
	}
}
Exemplo n.º 2
0
func HandleServiceChanges(receiver chan *etcd.Response) {
	// Do an initial sync and then listen for any messages on the receiver
	// Go and fetch all the services from etcd
	etcdClient := clients.EtcdClient()

	if etcdClient == nil {
		fmt.Println("Couldn't connect to etcd")
		return
	}

	handleChange(etcdClient)
	for _ = range receiver {
		handleChange(etcdClient)
	}
}