40 lines
844 B
Go
40 lines
844 B
Go
|
|
package handlers
|
||
|
|
|
||
|
|
import (
|
||
|
|
"encoding/json"
|
||
|
|
"net/http"
|
||
|
|
"time"
|
||
|
|
)
|
||
|
|
|
||
|
|
// HealthResponse represents the health check response
|
||
|
|
type HealthResponse struct {
|
||
|
|
Status string `json:"status"`
|
||
|
|
Timestamp time.Time `json:"timestamp"`
|
||
|
|
Version string `json:"version"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// HealthHandler handles health check requests
|
||
|
|
type HealthHandler struct {
|
||
|
|
version string
|
||
|
|
}
|
||
|
|
|
||
|
|
// NewHealthHandler creates a new health handler
|
||
|
|
func NewHealthHandler(version string) *HealthHandler {
|
||
|
|
return &HealthHandler{
|
||
|
|
version: version,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Check performs a health check
|
||
|
|
func (h *HealthHandler) Check(w http.ResponseWriter, r *http.Request) {
|
||
|
|
response := HealthResponse{
|
||
|
|
Status: "ok",
|
||
|
|
Timestamp: time.Now(),
|
||
|
|
Version: h.version,
|
||
|
|
}
|
||
|
|
|
||
|
|
w.Header().Set("Content-Type", "application/json")
|
||
|
|
w.WriteHeader(http.StatusOK)
|
||
|
|
json.NewEncoder(w).Encode(response)
|
||
|
|
}
|