implemented api handlers

This commit is contained in:
ston1th 2021-04-08 00:34:54 +02:00
commit 372915e24d
15 changed files with 302 additions and 73 deletions

View file

@ -10,11 +10,6 @@ import (
clientv3 "go.etcd.io/etcd/client/v3"
)
var (
ErrKeyNotFound = errors.New("etcd: key not found")
ErrPrefixNotFound = errors.New("etcd: prefix not found")
)
type Cluster struct {
logr.Logger
cli *clientv3.Client
@ -56,8 +51,8 @@ func (c *Cluster) Get(k string) (v []byte, err error) {
return
}
func (c *Cluster) GetPrefix(k string) (m map[string][]byte, err error) {
r, err := c.cli.Get(c.ctx, c.kvPrefix+"/"+k, clientv3.WithPrefix())
func (c *Cluster) GetPrefix(pk string) (m map[string][]byte, err error) {
r, err := c.cli.Get(c.ctx, c.kvPrefix+"/"+pk, clientv3.WithPrefix())
if err != nil {
return
}
@ -67,8 +62,8 @@ func (c *Cluster) GetPrefix(k string) (m map[string][]byte, err error) {
}
m = make(map[string][]byte)
for _, kv := range r.Kvs {
k := strings.TrimPrefix(c.kvPrefix+"/", string(kv.Key))
m[k] = kv.Value
key := strings.TrimPrefix(string(kv.Key), c.kvPrefix+"/"+pk)
m[key] = kv.Value
}
return
}