mirror of
https://github.com/optim-enterprises-bv/databunker.git
synced 2025-11-02 19:07:46 +00:00
add api to check db status
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user