github.com/xmidt-org/webpa-common@v1.11.9/service/consul/client.go (about) 1 package consul 2 3 import ( 4 gokitconsul "github.com/go-kit/kit/sd/consul" 5 "github.com/hashicorp/consul/api" 6 ) 7 8 // Client extends the go-kit consul Client interface with behaviors specific to XMiDT 9 type Client interface { 10 gokitconsul.Client 11 12 // Datacenters returns the known datacenters from the catalog 13 Datacenters() ([]string, error) 14 } 15 16 // NewClient constructs a Client object which wraps the given hashicorp consul client. 17 // This factory function is the analog to go-kit's sd/consul.NewClient function. 18 func NewClient(c *api.Client) Client { 19 return client{ 20 gokitconsul.NewClient(c), 21 c, 22 } 23 } 24 25 // client implements go-kit's consul Client interface and extends it to the local Client interface 26 type client struct { 27 gokitconsul.Client 28 c *api.Client 29 } 30 31 func (c client) Datacenters() ([]string, error) { 32 return c.c.Catalog().Datacenters() 33 }