Skip to content

Commit

Permalink
Adding basic consul client
Browse files Browse the repository at this point in the history
  • Loading branch information
armon committed Apr 27, 2014
1 parent d41aa4f commit e1bc86f
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions consul/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 prefixed by prefix.
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] = p.Value
}
}
return vars, nil
}

0 comments on commit e1bc86f

Please sign in to comment.