summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/xordataexchange/crypt/backend/consul
diff options
context:
space:
mode:
authorWim <wim@42.be>2018-08-06 21:47:05 +0200
committerWim <wim@42.be>2018-08-06 21:47:05 +0200
commit51062863a5c34d81e296cf15c61140911037cf3b (patch)
tree9b5e044672486326c7a0ca8fb26430f37bf4d83c /vendor/github.com/xordataexchange/crypt/backend/consul
parent4fb4b7aa6c02a54db8ad8dd98e4d321396926c0d (diff)
downloadmatterbridge-msglm-51062863a5c34d81e296cf15c61140911037cf3b.tar.gz
matterbridge-msglm-51062863a5c34d81e296cf15c61140911037cf3b.tar.bz2
matterbridge-msglm-51062863a5c34d81e296cf15c61140911037cf3b.zip
Use mod vendor for vendored directory (backwards compatible)
Diffstat (limited to 'vendor/github.com/xordataexchange/crypt/backend/consul')
-rw-r--r--vendor/github.com/xordataexchange/crypt/backend/consul/consul.go87
1 files changed, 0 insertions, 87 deletions
diff --git a/vendor/github.com/xordataexchange/crypt/backend/consul/consul.go b/vendor/github.com/xordataexchange/crypt/backend/consul/consul.go
deleted file mode 100644
index cf85ed53..00000000
--- a/vendor/github.com/xordataexchange/crypt/backend/consul/consul.go
+++ /dev/null
@@ -1,87 +0,0 @@
-package consul
-
-import (
- "fmt"
- "strings"
- "time"
-
- "github.com/xordataexchange/crypt/backend"
-
- "github.com/armon/consul-api"
-)
-
-type Client struct {
- client *consulapi.KV
- waitIndex uint64
-}
-
-func New(machines []string) (*Client, error) {
- conf := consulapi.DefaultConfig()
- if len(machines) > 0 {
- conf.Address = machines[0]
- }
- client, err := consulapi.NewClient(conf)
- if err != nil {
- return nil, err
- }
- return &Client{client.KV(), 0}, nil
-}
-
-func (c *Client) Get(key string) ([]byte, error) {
- kv, _, err := c.client.Get(key, nil)
- if err != nil {
- return nil, err
- }
- if kv == nil {
- return nil, fmt.Errorf("Key ( %s ) was not found.", key)
- }
- return kv.Value, nil
-}
-
-func (c *Client) List(key string) (backend.KVPairs, error) {
- pairs, _, err := c.client.List(key, nil)
- if err != nil {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- ret := make(backend.KVPairs, len(pairs), len(pairs))
- for i, kv := range pairs {
- ret[i] = &backend.KVPair{Key: kv.Key, Value: kv.Value}
- }
- return ret, nil
-}
-
-func (c *Client) Set(key string, value []byte) error {
- key = strings.TrimPrefix(key, "/")
- kv := &consulapi.KVPair{
- Key: key,
- Value: value,
- }
- _, err := c.client.Put(kv, nil)
- return err
-}
-
-func (c *Client) Watch(key string, stop chan bool) <-chan *backend.Response {
- respChan := make(chan *backend.Response, 0)
- go func() {
- for {
- opts := consulapi.QueryOptions{
- WaitIndex: c.waitIndex,
- }
- keypair, meta, err := c.client.Get(key, &opts)
- if keypair == nil && err == nil {
- err = fmt.Errorf("Key ( %s ) was not found.", key)
- }
- if err != nil {
- respChan <- &backend.Response{nil, err}
- time.Sleep(time.Second * 5)
- continue
- }
- c.waitIndex = meta.LastIndex
- respChan <- &backend.Response{keypair.Value, nil}
- }
- }()
- return respChan
-}