diff --git a/cmd/main.go b/cmd/main.go index 54ec4d7..55d3d49 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -9,6 +9,7 @@ import ( echoSwagger "github.com/swaggo/echo-swagger" logins "gitlab.g3e.fr/h6n/users/internal" "gitlab.g3e.fr/h6n/users/lib" + "gitlab.g3e.fr/h6n/users/lib/health" "gorm.io/gorm" _ "github.com/lib/pq" @@ -39,7 +40,7 @@ func isLoggedIn(c echo.Context) error { return c.NoContent(http.StatusNoContent) } -func health(c echo.Context) error { +func status(c echo.Context) error { return c.NoContent(http.StatusOK) } @@ -58,20 +59,14 @@ 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 - } if len(c.Path()) > 9 && c.Path()[:9] == "/swagger/" { return true } - return false + return health.IsHealth(c) } func skip_log(c echo.Context) bool { - if c.Request().Method == "GET" && c.Path() == "/health" { - return true - } - return false + return health.IsHealth(c) } // @title Users @@ -109,7 +104,7 @@ func main() { e.GET("/", isLoggedIn) e.POST("/", login) e.DELETE("/", logout) - e.GET("/health", health) + e.GET("/health", status) e.GET("/swagger/*", echoSwagger.WrapHandler) // Start server diff --git a/lib/health/isHealth.go b/lib/health/isHealth.go new file mode 100644 index 0000000..7cac15c --- /dev/null +++ b/lib/health/isHealth.go @@ -0,0 +1,10 @@ +package health + +import "github.com/labstack/echo/v4" + +func IsHealth(c echo.Context) bool { + if c.Request().Method == "GET" && c.Path() == "/health" { + return true + } + return false +}