update new route middlewares
This commit is contained in:
+24
-4
@@ -1,22 +1,42 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"go-api/pkg/context"
|
||||
"go-api/router/controller"
|
||||
"go-api/router/middleware"
|
||||
"os"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var patch = context.PatchContext
|
||||
|
||||
// New web server engine
|
||||
func New() *gin.Engine {
|
||||
e := gin.New()
|
||||
|
||||
e.Use(gin.Logger())
|
||||
e.Use(gin.Recovery())
|
||||
e.Use(middleware.Cors())
|
||||
|
||||
// if in release mode dont serve swagger api docs
|
||||
if os.Getenv("RELEASE") != "1" {
|
||||
// serve static swagger ui
|
||||
e.Use(middleware.SwaggerServe("/api-docs", nil))
|
||||
}
|
||||
|
||||
return e
|
||||
}
|
||||
|
||||
// SetRoute setup all routes
|
||||
func SetRoute(e *gin.Engine) {
|
||||
e.GET("/", func(c *gin.Context) {
|
||||
c.String(http.StatusOK, "ok")
|
||||
})
|
||||
e.GET("/", patch(controller.Health()))
|
||||
|
||||
// if in release mode dont serve swagger api docs
|
||||
if os.Getenv("RELEASE") != "1" {
|
||||
e.GET("/api-docs.json", middleware.SwaggerSpecServe())
|
||||
}
|
||||
|
||||
api := e.Group("/api", patch(middleware.ServerPanicCatch()))
|
||||
_ = api
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user