Building agents in Go that talk with Consul agent

Consul makes it simple for services to register themselves and to discover other services via a DNS or HTTP interface, provides built-in health checks, and more. It also includes a key-value store similar to Etcd or Zookeeper.

I’m starting to think of a local Consul agent – either running in client or server mode – as a foundation block of my operating system. On-server orchestration software can then talk to its local Consul agent (via HTTP API)

My language of choice for this orchestration software is Go. Easy to build small service apps, and easy to distribute and run them.

There is already a Go client for the key-value store API: consul-kv written by Armon Dadgar the creator of Consul.

Now there is a Go client for the services/health check API: consul-discovery

Here is an example app to request the available services and display the Go structs:

package main
import (
func main() {
	client, _ := consuldiscovery.NewClient(consuldiscovery.DefaultConfig())
	services, _ := client.CatalogServices()
  fmt.Printf("Services: %#v\n\n", services)
  for _, service := range services {
    serviceNodes, _ := client.CatalogServiceByName(service.Name)
    fmt.Printf("%s: %#v\n", service.Name, serviceNodes)

Spread the word

twitter icon facebook icon linkedin icon