sneak
9f3fb1e944
* updated healthcheck a bit * added maintenance mode config toggle * added recovery handler
31 lines
817 B
Go
31 lines
817 B
Go
package httpserver
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
func (s *server) handleHealthCheck() http.HandlerFunc {
|
|
type response struct {
|
|
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"`
|
|
}
|
|
return func(w http.ResponseWriter, req *http.Request) {
|
|
resp := &response{
|
|
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,
|
|
}
|
|
s.respondJSON(w, req, resp, 200)
|
|
}
|
|
}
|