28 lines
600 B
Go
28 lines
600 B
Go
package httpserver
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
func (s *server) handleHealthCheck() http.HandlerFunc {
|
|
type response struct {
|
|
Status string `json:"status"`
|
|
Now string `json:"now"`
|
|
Uptime string `json:"uptime"`
|
|
Version string `json:"version"`
|
|
Appname string `json:"appname"`
|
|
}
|
|
return func(w http.ResponseWriter, req *http.Request) {
|
|
resp := &response{
|
|
Status: "ok",
|
|
Now: time.Now().UTC().Format(time.RFC3339Nano),
|
|
Uptime: fmt.Sprintf("%f", s.uptime().Seconds()),
|
|
Appname: s.appname,
|
|
Version: s.version,
|
|
}
|
|
s.respondJSON(w, req, resp, 200)
|
|
}
|
|
}
|