forked from kelseyhightower/confd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
39 lines (35 loc) · 823 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
31
32
33
34
35
36
37
38
39
package consul
import (
"github.com/armon/consul-kv"
)
// Client provides a wrapper around the consulkv client
type Client struct {
client *consulkv.Client
}
// NewConsulClient returns a new client to Consul for the given address
func NewConsulClient(addr string) (*Client, error) {
conf := consulkv.DefaultConfig()
conf.Address = addr
client, err := consulkv.NewClient(conf)
if err != nil {
return nil, err
}
c := &Client{
client: client,
}
return c, nil
}
// GetValues queries Consul for keys
func (c *Client) GetValues(keys []string) (map[string]interface{}, error) {
vars := make(map[string]interface{})
for _, key := range keys {
_, pairs, err := c.client.List(key)
if err != nil {
return vars, err
}
for _, p := range pairs {
vars[p.Key] = string(p.Value)
}
}
return vars, nil
}