bottin-ag/apihandler/apihandler.go
Victor Lacasse-Beaudoin dc72748fbe Implémenter route /v0/health
Ajouter error type si dbclient ou bottinclient ne sont pas implémentés

Ajouter echo.Group v0
2023-09-15 18:13:48 -04:00

47 lines
1.1 KiB
Go

// Package apihandler provides handlers for API routes
package apihandler
import (
"net/http"
"git.agecem.com/agecem/bottin-ag/apierror"
"git.agecem.com/agecem/bottin-ag/apiresponse"
"github.com/labstack/echo/v4"
)
// DeclareRoutes declares the API server endpoints for the specified Group
func DeclareRoutes(e *echo.Group, h *APIHandler) {
e.GET("/health/", h.HealthGET)
}
func New() (handler *APIHandler) {
return
}
/*
APIHandler is the struct that implements the actual logic for the API server
routes
*/
type APIHandler struct{}
// HealthGET is the handler for `GET /v:version/health/ http/1.1`
func (a *APIHandler) HealthGET(c echo.Context) error {
var r apiresponse.HealthGET
// TODO
r.Data.BottinStatus = "not implemented"
// TODO
r.Data.DBStatus = "not implemented"
if r.Data.BottinStatus == "not implemented" || r.Data.DBStatus == "not implemented" {
var err apierror.ErrBottinOrDBNotImplemented
r.Error = err.Error()
r.StatusCode = http.StatusInternalServerError
r.Message = "not ok"
return c.JSON(r.StatusCode, r)
}
return c.JSON(r.StatusCode, r)
}