Skip to content

Go package is a service discovery client for Consul

Notifications You must be signed in to change notification settings

skailhq/consul-discovery

 
 

Repository files navigation

consul-discovery

This Go package is a service discovery client for Consul.

Related: see consul-kv for a key-value client package to Consul.

Documentation

The full documentation is available on Godoc

Usage

Below is an example of using the Consul Discovery client:

client, _ := consuldiscovery.NewClient(consuldiscovery.DefaultConfig())
criticalChecks, _ := client.HealthByState("critical")

services, _ := client.CatalogServices()
serviceNodes, _ := client.CatalogServiceByName(services[0].Name)

Also see examples folder for runnable examples.

First, run the consul agent command:

consul agent -data-dir /tmp/consul -server -bootstrap -config-dir testconfig

Now the examples can be run on this example local consul node:

$ go run examples/catalog.go
Services: consuldiscovery.CatalogServices{consuldiscovery.CatalogService{Name:"consul"...}

consul: consuldiscovery.CatalogServiceByName{consuldiscovery.CatalogServiceNode{Node:"skailhq.local"...}
simple_service: consuldiscovery.CatalogServiceByName{consuldiscovery.CatalogServiceNode{Node:"skailhq.local"...}

Development

To run the tests, first run a consul server with API port 8500:

consul agent -data-dir /tmp/consul -server -bootstrap -config-dir testconfig

The run tests:

go test

About

Go package is a service discovery client for Consul

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%