OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / go-kit / kit / sd / consul / client.go
1 package consul
2
3 import (
4         consul "github.com/hashicorp/consul/api"
5 )
6
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
11
12         // Deregister a service with the local agent.
13         Deregister(r *consul.AgentServiceRegistration) error
14
15         // Service
16         Service(service, tag string, passingOnly bool, queryOpts *consul.QueryOptions) ([]*consul.ServiceEntry, *consul.QueryMeta, error)
17 }
18
19 type client struct {
20         consul *consul.Client
21 }
22
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}
27 }
28
29 func (c *client) Register(r *consul.AgentServiceRegistration) error {
30         return c.consul.Agent().ServiceRegister(r)
31 }
32
33 func (c *client) Deregister(r *consul.AgentServiceRegistration) error {
34         return c.consul.Agent().ServiceDeregister(r.ID)
35 }
36
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)
39 }