forked from go-kit/kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
30 lines (25 loc) · 781 Bytes
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package consul
import consul "github.com/hashicorp/consul/api"
// Client is a wrapper around the Consul API.
type Client interface {
Service(service string, tag string, queryOpts *consul.QueryOptions) ([]*consul.ServiceEntry, *consul.QueryMeta, error)
}
type client struct {
consul *consul.Client
}
// NewClient returns an implementation of the Client interface expecting a fully
// setup Consul Client.
func NewClient(c *consul.Client) Client {
return &client{
consul: c,
}
}
// GetInstances returns the list of healthy entries for a given service filtered
// by tag.
func (c *client) Service(
service string,
tag string,
opts *consul.QueryOptions,
) ([]*consul.ServiceEntry, *consul.QueryMeta, error) {
return c.consul.Health().Service(service, tag, true, opts)
}