Add KV store in cluster DB

This commit is contained in:
Ingo Oppermann
2023-06-22 16:20:09 +02:00
parent db00144cab
commit e5f0b3a57f
6 changed files with 425 additions and 80 deletions

View File

@@ -49,6 +49,11 @@ type LockRequest struct {
ValidUntil time.Time `json:"valid_until"`
}
type SetKVRequest struct {
Key string `json:"key"`
Value string `json:"value"`
}
type APIClient struct {
Address string
Client *http.Client
@@ -196,6 +201,23 @@ func (c *APIClient) Unlock(origin string, name string) error {
return err
}
func (c *APIClient) SetKV(origin string, r SetKVRequest) error {
data, err := json.Marshal(r)
if err != nil {
return err
}
_, err = c.call(http.MethodPost, "/v1/kv", "application/json", bytes.NewReader(data), origin)
return err
}
func (c *APIClient) UnsetKV(origin string, key string) error {
_, err := c.call(http.MethodDelete, "/v1/kv/"+url.PathEscape(key), "application/json", nil, origin)
return err
}
func (c *APIClient) Snapshot() (io.ReadCloser, error) {
return c.stream(http.MethodGet, "/v1/snapshot", "", nil, "")
}