2022-11-28 00:19:47 +00:00
|
|
|
package server
|
2020-09-30 06:35:07 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *server) handleHealthCheck() http.HandlerFunc {
|
|
|
|
type response struct {
|
2020-10-03 05:40:33 +00:00
|
|
|
Status string `json:"status"`
|
|
|
|
Now string `json:"now"`
|
|
|
|
UptimeSeconds int64 `json:"uptime_seconds"`
|
|
|
|
UptimeHuman string `json:"uptime_human"`
|
|
|
|
Version string `json:"version"`
|
|
|
|
Appname string `json:"appname"`
|
|
|
|
Maintenance bool `json:"maintenance_mode"`
|
2020-09-30 06:35:07 +00:00
|
|
|
}
|
|
|
|
return func(w http.ResponseWriter, req *http.Request) {
|
|
|
|
resp := &response{
|
2020-10-03 05:40:33 +00:00
|
|
|
Status: "ok",
|
|
|
|
Now: time.Now().UTC().Format(time.RFC3339Nano),
|
|
|
|
UptimeSeconds: int64(s.uptime().Seconds()),
|
|
|
|
UptimeHuman: s.uptime().String(),
|
|
|
|
Maintenance: s.maintenance(),
|
|
|
|
Appname: s.appname,
|
|
|
|
Version: s.version,
|
2020-09-30 06:35:07 +00:00
|
|
|
}
|
|
|
|
s.respondJSON(w, req, resp, 200)
|
|
|
|
}
|
|
|
|
}
|