aboutsummaryrefslogtreecommitdiff
path: root/httpd.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-04-16 01:36:20 +0700
committerShulhan <ms@kilabit.info>2022-04-16 18:32:36 +0700
commit8947cc8b6a9751b3cae3d4d22fdf3ac154f77dfd (patch)
tree7251c221bc3d4a324a6bdaca7a215d75bbb310ca /httpd.go
parentdfc441b32458d204dae6498867f08e7da483c815 (diff)
downloadrescached-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.go26
1 files changed, 21 insertions, 5 deletions
diff --git a/httpd.go b/httpd.go
index 7eacaa1..c698bf4 100644
--- a/httpd.go
+++ b/httpd.go
@@ -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()