diff options
| author | Shulhan <ms@kilabit.info> | 2022-05-22 21:47:09 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2022-05-22 21:51:48 +0700 |
| commit | 3a38245a6a418b2ddbe4dfcd916ab83708b6f500 (patch) | |
| tree | 5e7972a3ba569fb0269bbf573d8a7ad719540075 /httpd.go | |
| parent | 0b92dbb8463dee31c005c59f67c2bf754a9eae12 (diff) | |
| download | rescached-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 'httpd.go')
| -rw-r--r-- | httpd.go | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -119,6 +119,17 @@ func (srv *Server) httpdRegisterEndpoints() (err error) { } err = srv.httpd.RegisterEndpoint(&libhttp.Endpoint{ + Method: libhttp.RequestMethodGet, + Path: apiBlockd, + RequestType: libhttp.RequestTypeNone, + ResponseType: libhttp.ResponseTypeJSON, + Call: srv.httpApiBlockdList, + }) + if err != nil { + return err + } + + err = srv.httpd.RegisterEndpoint(&libhttp.Endpoint{ Method: libhttp.RequestMethodPost, Path: apiBlockd, RequestType: libhttp.RequestTypeJSON, @@ -301,6 +312,34 @@ func (srv *Server) httpdRun() { } } +// httpApiBlockdList fetch the list of block.d files. +// +// # Request +// +// GET /api/block.d +// +// # Response +// +// On success it will return list of hosts in block.d, +// +// { +// "data": { +// "<name>": <Blockd> +// ... +// } +// } +func (srv *Server) httpApiBlockdList(epr *libhttp.EndpointRequest) (resBody []byte, err error) { + var ( + res = libhttp.EndpointResponse{} + ) + + res.Code = http.StatusOK + res.Data = srv.env.HostBlockd + + resBody, err = json.Marshal(&res) + return resBody, err +} + // httpApiBlockdDisable disable the hosts block.d. func (srv *Server) httpApiBlockdDisable(epr *libhttp.EndpointRequest) (resBody []byte, err error) { var ( |
