Files
thamanyah/discovery/internal/handlers/handlers.go
T
FahdShalhoub 98950aba20
Build, Push and Deploy Discovery / build-push-deploy (push) Successful in 1m45s
Deploy Infrastructure / pulumi-up (push) Successful in 2s
FEAT: Init Discovery Service
2026-08-27 22:03:41 +03:00

42 lines
1.2 KiB
Go

package handlers
import (
"encoding/json"
"log"
"net/http"
"thamanyah/discovery/internal/api"
)
// Health is the liveness probe the ALB target group polls.
//
// @Summary Health check
// @Description Reports that the service is up and serving. Used as the ALB target group health check; it does not verify the database connection.
// @Tags system
// @Produce json
// @Success 200 {object} api.HealthResponse
// @Router /health [get]
func Health(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusOK, api.HealthResponse{Status: "ok"})
}
func writeJSON(w http.ResponseWriter, status int, body any) {
writeJSONContent(w, "application/json", status, body)
}
func writeProblem(w http.ResponseWriter, status int, title, detail string) {
writeJSONContent(w, "application/problem+json", status, api.ProblemDetails{
Type: "about:blank",
Title: title,
Status: status,
Detail: detail,
})
}
func writeJSONContent(w http.ResponseWriter, contentType string, status int, body any) {
w.Header().Set("Content-Type", contentType)
w.WriteHeader(status)
if err := json.NewEncoder(w).Encode(body); err != nil {
log.Printf("Something Went Wrong Writing The Response: %s", err)
}
}