27 lines
486 B
Go
27 lines
486 B
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/noderunners/nip05api/internal/db"
|
|
)
|
|
|
|
type Health struct {
|
|
DB *db.DB
|
|
Version string
|
|
}
|
|
|
|
func (h *Health) Handle(w http.ResponseWriter, r *http.Request) {
|
|
if err := h.DB.Ping(r.Context()); err != nil {
|
|
WriteJSON(w, http.StatusServiceUnavailable, map[string]string{
|
|
"status": "down",
|
|
"version": h.Version,
|
|
})
|
|
return
|
|
}
|
|
WriteJSON(w, http.StatusOK, map[string]string{
|
|
"status": "ok",
|
|
"version": h.Version,
|
|
})
|
|
}
|