Add healthcheck endpoint (#170)

This commit is contained in:
Thomas Miceli
2023-12-16 01:27:00 +01:00
parent 246f12c8cb
commit 47869a77c9
4 changed files with 36 additions and 1 deletions

View File

@ -0,0 +1,24 @@
package web
import (
"github.com/labstack/echo/v4"
"github.com/thomiceli/opengist/internal/db"
"time"
)
func healthcheck(ctx echo.Context) error {
// Check database connection
dbOk := "ok"
httpStatus := 200
err := db.Ping()
if err != nil {
dbOk = "ko"
httpStatus = 503
}
return ctx.JSON(httpStatus, map[string]interface{}{
"database": dbOk,
"time": time.Now().Format(time.RFC3339),
})
}