add api to check db status

This commit is contained in:
root
2020-08-31 17:10:18 +00:00
parent f72c446cff
commit c87c841feb
2 changed files with 19 additions and 0 deletions

View File

@@ -153,12 +153,26 @@ func (e mainEnv) backupDB(w http.ResponseWriter, r *http.Request, ps httprouter.
e.db.store.BackupDB(w)
}
func (e mainEnv) checkStatus(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
err := e.db.store.Ping()
if err != nil {
w.WriteHeader(500)
w.Write([]byte("error"))
} else {
w.WriteHeader(200)
w.Write([]byte("OK"))
}
}
// setupRouter() setup HTTP Router object.
func (e mainEnv) setupRouter() *httprouter.Router {
box := packr.NewBox("../ui")
router := httprouter.New()
router.GET("/v1/status", e.checkStatus)
router.GET("/status", e.checkStatus)
router.GET("/v1/sys/backup", e.backupDB)
router.POST("/v1/user", e.userNew)

View File

@@ -174,6 +174,11 @@ func InitDB(filepath *string) (DBStorage, error){
return dbobj, nil
}
func (dbobj DBStorage) Ping() error {
return dbobj.db.Ping()
}
// CloseDB function closes the open database
func (dbobj DBStorage) CloseDB() {
dbobj.db.Close()