gohttpserver/internal/server/handlehealthcheck.go

31 lines
813 B
Go
Raw Normal View History

package server
2020-09-30 06:35:07 +00:00
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"`
2020-09-30 06:35:07 +00:00
}
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,
2020-09-30 06:35:07 +00:00
}
s.respondJSON(w, req, resp, 200)
}
}