diff options
| author | Shulhan <ms@kilabit.info> | 2022-04-16 01:36:20 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2022-04-16 18:32:36 +0700 |
| commit | 8947cc8b6a9751b3cae3d4d22fdf3ac154f77dfd (patch) | |
| tree | 7251c221bc3d4a324a6bdaca7a215d75bbb310ca /httpd.go | |
| parent | dfc441b32458d204dae6498867f08e7da483c815 (diff) | |
| download | rescached-8947cc8b6a9751b3cae3d4d22fdf3ac154f77dfd.tar.xz | |
all: apply suggestions from linter
List of changes,
* Remove unused constants keyIsEnabled, keyIsSystem, and keyLastUpdated.
* Use the method String on instance of Duration instead of fmt.Sprintf.
* Replace any usage of io/ioutil package with its replacement.
* Check for error from calling Environment.init and Zone.Add.
* Prefix all returned error on hostsBlock.update method.
* Add "lint" task as part of default target, build.
Diffstat (limited to 'httpd.go')
| -rw-r--r-- | httpd.go | 26 |
1 files changed, 21 insertions, 5 deletions
@@ -325,6 +325,7 @@ func (srv *Server) httpdAPIGetEnvironment(epr *libhttp.EndpointRequest) (resBody func (srv *Server) httpdAPIPostEnvironment(epr *libhttp.EndpointRequest) (resBody []byte, err error) { var ( + logp = "httpdAPIPostEnvironment" res = libhttp.EndpointResponse{} newOpts = new(Environment) ) @@ -342,7 +343,12 @@ func (srv *Server) httpdAPIPostEnvironment(epr *libhttp.EndpointRequest) (resBod return nil, &res } - newOpts.init() + err = newOpts.init() + if err != nil { + res.Code = http.StatusInternalServerError + res.Message = fmt.Sprintf("%s: %s", logp, err) + return nil, &res + } fmt.Printf("new options: %+v\n", newOpts) @@ -474,17 +480,22 @@ func (srv *Server) hostsBlockEnable(hb *hostsBlock) (err error) { } func (srv *Server) hostsBlockDisable(hb *hostsBlock) (err error) { - var hfile *dns.HostsFile + var ( + logp = "hostsBlockDisable" + + hfile *dns.HostsFile + ) + hfile = srv.env.HostsFiles[hb.Name] if hfile == nil { - return fmt.Errorf("unknown hosts block: %q", hb.Name) + return fmt.Errorf("%s: unknown hosts block: %q", logp, hb.Name) } srv.dns.RemoveLocalCachesByNames(hfile.Names()) err = hb.hide() if err != nil { - return err + return fmt.Errorf("%s: %w", logp, err) } delete(srv.env.HostsFiles, hb.Name) @@ -872,7 +883,12 @@ func (srv *Server) apiZoneRRCreate(epr *libhttp.EndpointRequest) (resbody []byte } // Update the Zone file. - zoneFile.Add(rr) + err = zoneFile.Add(rr) + if err != nil { + res.Message = err.Error() + return nil, &res + } + err = zoneFile.Save() if err != nil { res.Message = err.Error() |
