v1.0.0: health: add a simple healthcheck

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2024-03-15 18:56:54 +01:00
commit c78316301f
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
2 changed files with 32 additions and 1 deletions

View file

@ -23,6 +23,10 @@ func isLoggedIn(c echo.Context) error {
return c.NoContent(http.StatusNoContent)
}
func health(c echo.Context) error {
return c.NoContent(http.StatusOK)
}
func init_database() {
var err error
@ -38,6 +42,16 @@ func skip_auth(c echo.Context) bool {
if c.Request().Method == "POST" && c.Path() == "/" {
return true
}
if c.Request().Method == "GET" && c.Path() == "/health" {
return true
}
return false
}
func skip_log(c echo.Context) bool {
if c.Request().Method == "GET" && c.Path() == "/health" {
return true
}
return false
}
@ -50,7 +64,9 @@ func main() {
e := echo.New()
// Middleware
e.Use(middleware.Logger())
e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
Skipper: skip_log,
}))
e.Use(middleware.Recover())
e.Use(middleware.CORS())
e.Use(lib.AuthMiddleware(skip_auth))
@ -59,6 +75,7 @@ func main() {
e.GET("/", isLoggedIn)
e.POST("/", login)
e.DELETE("/", logout)
e.GET("/health", health)
// Start server
e.Logger.Fatal(e.Start(":1222"))