Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
package main
import (
func main() {
client, err := consulcatalog.NewClient(consulcatalog.DefaultConfig())
if err != nil {
var index uint64
var nodes consulcatalog.Nodes
service := os.Args[1]
for {
log.Printf("Get blocking query service %s index %d ...", service, index)
meta, newNodes, err := client.Get("service", service, index)
if err != nil {
log.Printf("error: %s", err)
time.Sleep(5 * time.Second)
log.Printf("new index: %v", meta.ModifyIndex)
index = meta.ModifyIndex
if reflect.DeepEqual(nodes, newNodes) {
log.Println("no Nodes changed.")
} else {
jsonBytes, _ := json.Marshal(newNodes)
log.Printf("Nodes changed. %s", jsonBytes)
nodes = newNodes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment