4 consul "github.com/hashicorp/consul/api"
7 // Client is a wrapper around the Consul API.
8 type Client interface {
9 // Register a service with the local agent.
10 Register(r *consul.AgentServiceRegistration) error
12 // Deregister a service with the local agent.
13 Deregister(r *consul.AgentServiceRegistration) error
16 Service(service, tag string, passingOnly bool, queryOpts *consul.QueryOptions) ([]*consul.ServiceEntry, *consul.QueryMeta, error)
23 // NewClient returns an implementation of the Client interface, wrapping a
24 // concrete Consul client.
25 func NewClient(c *consul.Client) Client {
26 return &client{consul: c}
29 func (c *client) Register(r *consul.AgentServiceRegistration) error {
30 return c.consul.Agent().ServiceRegister(r)
33 func (c *client) Deregister(r *consul.AgentServiceRegistration) error {
34 return c.consul.Agent().ServiceDeregister(r.ID)
37 func (c *client) Service(service, tag string, passingOnly bool, queryOpts *consul.QueryOptions) ([]*consul.ServiceEntry, *consul.QueryMeta, error) {
38 return c.consul.Health().Service(service, tag, passingOnly, queryOpts)