diff options
| author | Shulhan <ms@kilabit.info> | 2022-06-11 01:48:50 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2022-06-12 13:02:21 +0700 |
| commit | b76e182e94f55ce542ba336ea35bcb108e924c3f (patch) | |
| tree | 9b682de074402632a5c96f12df4f9ba7ad1d8da1 | |
| parent | 8c8619d939e57c42dcb28c3f680ec9a3c6d075fa (diff) | |
| download | rescached-b76e182e94f55ce542ba336ea35bcb108e924c3f.tar.xz | |
all: make GET /api/hosts.d to return list of hosts.d if name is empty
This is to provide an HTTP API to fetch list of hosts.d files on the
server.
| -rw-r--r-- | httpd.go | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -925,8 +925,16 @@ func (srv *Server) apiHostsdDelete(epr *libhttp.EndpointRequest) (resbody []byte // // # Request // +// Format, +// // GET /api/hosts.d?name=<name> // +// Parameters, +// +// - name: string, optional, the name of hosts file where content to be +// fetch. +// If its empty, it will return all hosts files. +// // # Response // // On success, it will return list of resource record in JSON format. @@ -939,6 +947,13 @@ func (srv *Server) apiHostsdGet(epr *libhttp.EndpointRequest) (resbody []byte, e found bool ) + name = strings.TrimSpace(name) + if len(name) == 0 { + res.Code = http.StatusOK + res.Data = srv.env.HostsFiles + return json.Marshal(&res) + } + hf, found = srv.env.HostsFiles[name] if !found { res.Code = http.StatusNotFound |
