aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-05-22 21:47:09 +0700
committerShulhan <ms@kilabit.info>2022-05-22 21:51:48 +0700
commit3a38245a6a418b2ddbe4dfcd916ab83708b6f500 (patch)
tree5e7972a3ba569fb0269bbf573d8a7ad719540075 /client.go
parent0b92dbb8463dee31c005c59f67c2bf754a9eae12 (diff)
downloadrescached-3a38245a6a418b2ddbe4dfcd916ab83708b6f500.tar.xz
all: implement HTTP API to fetch list of block.d
Given the following request, GET /api/block.d It will return list of hosts in block.d as JSON format: { "data": { "<name>": <Blockd> ... } }
Diffstat (limited to 'client.go')
-rw-r--r--client.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/client.go b/client.go
index 53e057b..480fe53 100644
--- a/client.go
+++ b/client.go
@@ -33,6 +33,33 @@ func NewClient(serverUrl string, insecure bool) (cl *Client) {
return cl
}
+// Blockd return list of all block.d files on the server.
+func (cl *Client) Blockd() (hostBlockd map[string]*Blockd, err error) {
+ var (
+ logp = "Blockd"
+ res = libhttp.EndpointResponse{}
+
+ resb []byte
+ )
+
+ _, resb, err = cl.Get(apiBlockd, nil, nil)
+ if err != nil {
+ return nil, fmt.Errorf("%s: %w", logp, err)
+ }
+
+ res.Data = &hostBlockd
+
+ err = json.Unmarshal(resb, &res)
+ if err != nil {
+ return nil, fmt.Errorf("%s: %w", logp, err)
+ }
+ if res.Code != http.StatusOK {
+ return nil, fmt.Errorf("%s: %d %s", logp, res.Code, res.Message)
+ }
+
+ return hostBlockd, nil
+}
+
// BlockdDisable disable specific hosts on block.d.
func (cl *Client) BlockdDisable(blockdName string) (an interface{}, err error) {
var (