aboutsummaryrefslogtreecommitdiff
path: root/httpd.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-04-16 22:30:27 +0700
committerShulhan <ms@kilabit.info>2022-04-16 22:30:27 +0700
commit0156deaaaa0edbb93cfbf60a8cac99fc17d63a60 (patch)
tree0e373dd81bf402acc78ddc19356f78cb81d5cdb2 /httpd.go
parent8947cc8b6a9751b3cae3d4d22fdf3ac154f77dfd (diff)
downloadrescached-0156deaaaa0edbb93cfbf60a8cac99fc17d63a60.tar.xz
cmd/resolver: implement sub command to update environment
The env command now accept sub command "update" with argument path to the file or "-" for standard input. The content of file is formatted using JSON, the same as output of "env" command. If the content of file is valid, server will be restarted immediately.
Diffstat (limited to 'httpd.go')
-rw-r--r--httpd.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/httpd.go b/httpd.go
index c698bf4..6e51ddf 100644
--- a/httpd.go
+++ b/httpd.go
@@ -98,15 +98,15 @@ func (srv *Server) httpdRegisterEndpoints() (err error) {
return err
}
- epAPIPostEnvironment := &libhttp.Endpoint{
+ apiEnvironmentUpdate := &libhttp.Endpoint{
Method: libhttp.RequestMethodPost,
Path: apiEnvironment,
RequestType: libhttp.RequestTypeJSON,
ResponseType: libhttp.ResponseTypeJSON,
- Call: srv.httpdAPIPostEnvironment,
+ Call: srv.httpApiEnvironmentUpdate,
}
- err = srv.httpd.RegisterEndpoint(epAPIPostEnvironment)
+ err = srv.httpd.RegisterEndpoint(apiEnvironmentUpdate)
if err != nil {
return err
}
@@ -323,9 +323,9 @@ func (srv *Server) httpdAPIGetEnvironment(epr *libhttp.EndpointRequest) (resBody
return json.Marshal(&res)
}
-func (srv *Server) httpdAPIPostEnvironment(epr *libhttp.EndpointRequest) (resBody []byte, err error) {
+func (srv *Server) httpApiEnvironmentUpdate(epr *libhttp.EndpointRequest) (resBody []byte, err error) {
var (
- logp = "httpdAPIPostEnvironment"
+ logp = "httpApiEnvironmentUpdate"
res = libhttp.EndpointResponse{}
newOpts = new(Environment)
)
@@ -371,6 +371,8 @@ func (srv *Server) httpdAPIPostEnvironment(epr *libhttp.EndpointRequest) (resBod
res.Code = http.StatusOK
res.Message = "Restarting DNS server"
+ res.Data = newOpts
+
return json.Marshal(&res)
}