diff options
| author | Shulhan <ms@kilabit.info> | 2022-04-20 01:19:39 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2022-04-20 01:19:39 +0700 |
| commit | 80718f34042298ccef7db0396471d2e00d60d893 (patch) | |
| tree | 785ea6281d6de542b66add71e56b74e254ca05eb /client.go | |
| parent | 289bb8e6bd9e6d8dcad93f92a1602779170c7fe6 (diff) | |
| download | rescached-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.go | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -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 ( |
