bottin/routes.go

46 lines
1 KiB
Go
Raw Normal View History

package main
import (
"fmt"
"net/http"
"codeberg.org/vlbeaudoin/pave/v2"
"codeberg.org/vlbeaudoin/voki/v3"
"github.com/labstack/echo/v4"
)
func addRoutes(e *echo.Echo, db *PostgresClient) error {
_ = db
apiPath := "/api"
apiGroup := e.Group(apiPath)
p := pave.New()
if err := pave.EchoRegister[HealthGETRequest](
apiGroup,
&p,
apiPath,
http.MethodGet,
"/health/",
"Get API server health",
"HealthGET", func(c echo.Context) error {
var request, response = HealthGETRequest{}, HealthGETResponse{}
if !request.Complete() {
var response voki.ResponseBadRequest
response.Message = "Incomplete HealthGET request received"
return c.JSON(response.StatusCode(), response)
}
if err := response.SetStatusCode(http.StatusOK); err != nil {
var response voki.ResponseInternalServerError
response.Message = fmt.Sprintf("handler: %s", err)
return c.JSON(response.StatusCode(), response)
}
response.Message = "ok"
return c.JSON(response.StatusCode(), response)
}); err != nil {
return err
}
return nil
}