From b76e182e94f55ce542ba336ea35bcb108e924c3f Mon Sep 17 00:00:00 2001 From: Shulhan Date: Sat, 11 Jun 2022 01:48:50 +0700 Subject: 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. --- httpd.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/httpd.go b/httpd.go index 2e50b45..09ac8c8 100644 --- a/httpd.go +++ b/httpd.go @@ -925,8 +925,16 @@ func (srv *Server) apiHostsdDelete(epr *libhttp.EndpointRequest) (resbody []byte // // # Request // +// Format, +// // GET /api/hosts.d?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 -- cgit v1.3