mirror of
https://github.com/datarhei/core.git
synced 2025-10-23 16:03:14 +08:00
Add KV store in cluster DB
This commit is contained in:
@@ -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, "")
|
||||
}
|
||||
|
Reference in New Issue
Block a user