aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-04-20 01:19:39 +0700
committerShulhan <ms@kilabit.info>2022-04-20 01:19:39 +0700
commit80718f34042298ccef7db0396471d2e00d60d893 (patch)
tree785ea6281d6de542b66add71e56b74e254ca05eb /client.go
parent289bb8e6bd9e6d8dcad93f92a1602779170c7fe6 (diff)
downloadrescached-80718f34042298ccef7db0396471d2e00d60d893.tar.xz
cmd/resolver: implement command to update block.d hosts by its name
The following command: "resolver block.d update x" will fetch the latest hosts file from the block.d provider "x" based on its registered URL.
Diffstat (limited to 'client.go')
-rw-r--r--client.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/client.go b/client.go
index 524322e..381b872 100644
--- a/client.go
+++ b/client.go
@@ -32,6 +32,37 @@ func NewClient(serverUrl string, insecure bool) (cl *Client) {
return cl
}
+// BlockdUpdate fetch the latest hosts file from the hosts block
+// provider based on registered URL.
+func (cl *Client) BlockdUpdate(blockdName string) (an interface{}, err error) {
+ var (
+ logp = "BlockdUpdate"
+ hbReq = hostsBlock{
+ Name: blockdName,
+ }
+ res = libhttp.EndpointResponse{}
+
+ hb *hostsBlock
+ resb []byte
+ )
+
+ _, resb, err = cl.PostJSON(apiBlockdUpdate, nil, &hbReq)
+ if err != nil {
+ return nil, fmt.Errorf("%s: %w", logp, err)
+ }
+
+ res.Data = &hb
+ 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 hb, nil
+}
+
// Caches fetch all of non-local caches from server.
func (cl *Client) Caches() (answers []*dns.Answer, err error) {
var (