2020-04-08 22:29:11 +03:00
|
|
|
package routes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-11-01 22:14:10 +03:00
|
|
|
"gorm.io/gorm"
|
2020-04-08 22:29:11 +03:00
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
type HealthHandler struct {
|
2020-05-24 14:41:19 +03:00
|
|
|
db *gorm.DB
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewHealthHandler(db *gorm.DB) *HealthHandler {
|
|
|
|
return &HealthHandler{db: db}
|
2020-04-08 22:29:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *HealthHandler) ApiGet(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var dbStatus int
|
2020-11-01 22:14:10 +03:00
|
|
|
if sqlDb, err := h.db.DB(); err == nil {
|
|
|
|
if err := sqlDb.Ping(); err == nil {
|
|
|
|
dbStatus = 1
|
|
|
|
}
|
2020-04-08 22:29:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
w.Header().Set("Content-Type", "text/plain")
|
|
|
|
w.Write([]byte(fmt.Sprintf("app=1\ndb=%d", dbStatus)))
|
|
|
|
}
|