1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

Add health endpoint.

This commit is contained in:
Ferdinand Mütsch
2020-04-08 21:29:11 +02:00
parent cd197e855c
commit 7a74ae251c
3 changed files with 38 additions and 4 deletions

21
routes/health.go Normal file
View File

@@ -0,0 +1,21 @@
package routes
import (
"fmt"
"github.com/jinzhu/gorm"
"net/http"
)
type HealthHandler struct {
Db *gorm.DB
}
func (h *HealthHandler) ApiGet(w http.ResponseWriter, r *http.Request) {
var dbStatus int
if err := h.Db.DB().Ping(); err == nil {
dbStatus = 1
}
w.Header().Set("Content-Type", "text/plain")
w.Write([]byte(fmt.Sprintf("app=1\ndb=%d", dbStatus)))
}