forked from mtusi2026/mtusi2026lab2
25 lines
500 B
Go
25 lines
500 B
Go
package http
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
type healthResponse struct {
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
func healthLive(c echo.Context) error {
|
|
return c.JSON(http.StatusOK, healthResponse{Status: "ok"})
|
|
}
|
|
|
|
func healthReady(isReady func() bool) echo.HandlerFunc {
|
|
return func(c echo.Context) error {
|
|
if !isReady() {
|
|
return echo.NewHTTPError(http.StatusServiceUnavailable, "Service unavailable")
|
|
}
|
|
return c.JSON(http.StatusOK, healthResponse{Status: "ok"})
|
|
}
|
|
}
|