first commit
This commit is contained in:
26
internal/http/handlers/health.go
Normal file
26
internal/http/handlers/health.go
Normal file
@@ -0,0 +1,26 @@
|
||||
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,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user