Merge branch '10-issue' into 'main'
add health skip function in lib Closes #10 See merge request h6n/users!10
This commit is contained in:
commit
6e8f65223c
2 changed files with 15 additions and 10 deletions
15
cmd/main.go
15
cmd/main.go
|
|
@ -9,6 +9,7 @@ import (
|
||||||
echoSwagger "github.com/swaggo/echo-swagger"
|
echoSwagger "github.com/swaggo/echo-swagger"
|
||||||
logins "gitlab.g3e.fr/h6n/users/internal"
|
logins "gitlab.g3e.fr/h6n/users/internal"
|
||||||
"gitlab.g3e.fr/h6n/users/lib"
|
"gitlab.g3e.fr/h6n/users/lib"
|
||||||
|
"gitlab.g3e.fr/h6n/users/lib/health"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
|
|
@ -39,7 +40,7 @@ func isLoggedIn(c echo.Context) error {
|
||||||
return c.NoContent(http.StatusNoContent)
|
return c.NoContent(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func health(c echo.Context) error {
|
func status(c echo.Context) error {
|
||||||
return c.NoContent(http.StatusOK)
|
return c.NoContent(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,20 +59,14 @@ func skip_auth(c echo.Context) bool {
|
||||||
if c.Request().Method == "POST" && c.Path() == "/" {
|
if c.Request().Method == "POST" && c.Path() == "/" {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if c.Request().Method == "GET" && c.Path() == "/health" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
if len(c.Path()) > 9 && c.Path()[:9] == "/swagger/" {
|
if len(c.Path()) > 9 && c.Path()[:9] == "/swagger/" {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return health.IsHealth(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func skip_log(c echo.Context) bool {
|
func skip_log(c echo.Context) bool {
|
||||||
if c.Request().Method == "GET" && c.Path() == "/health" {
|
return health.IsHealth(c)
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @title Users
|
// @title Users
|
||||||
|
|
@ -109,7 +104,7 @@ func main() {
|
||||||
e.GET("/", isLoggedIn)
|
e.GET("/", isLoggedIn)
|
||||||
e.POST("/", login)
|
e.POST("/", login)
|
||||||
e.DELETE("/", logout)
|
e.DELETE("/", logout)
|
||||||
e.GET("/health", health)
|
e.GET("/health", status)
|
||||||
e.GET("/swagger/*", echoSwagger.WrapHandler)
|
e.GET("/swagger/*", echoSwagger.WrapHandler)
|
||||||
|
|
||||||
// Start server
|
// Start server
|
||||||
|
|
|
||||||
10
lib/health/isHealth.go
Normal file
10
lib/health/isHealth.go
Normal file
|
|
@ -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
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue