diff --git a/cmd/rqlited/main.go b/cmd/rqlited/main.go index 328cb91e..a3f058a9 100644 --- a/cmd/rqlited/main.go +++ b/cmd/rqlited/main.go @@ -159,9 +159,7 @@ func main() { if err != nil { log.Fatalf("failed to start auto-backups: %s", err.Error()) } - if backupSrv != nil { - httpServ.RegisterStatus("auto_backups", backupSrv) - } + httpServ.RegisterStatus("auto_backups", backupSrv) // Block until signalled. terminate := make(chan os.Signal, 1) diff --git a/http/service.go b/http/service.go index 76497020..1bdf25e4 100644 --- a/http/service.go +++ b/http/service.go @@ -432,6 +432,7 @@ func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // RegisterStatus allows other modules to register status for serving over HTTP. +// If stat is nil, the key is removed. func (s *Service) RegisterStatus(key string, stat StatusReporter) error { s.statusMu.Lock() defer s.statusMu.Unlock() @@ -439,6 +440,11 @@ func (s *Service) RegisterStatus(key string, stat StatusReporter) error { if _, ok := s.statuses[key]; ok { return fmt.Errorf("status already registered with key %s", key) } + + if stat == nil { + delete(s.statuses, key) + return nil + } s.statuses[key] = stat return nil