api-base/router/routes/routes.go
2020-08-16 17:39:13 +08:00

43 lines
815 B
Go

package routes
import (
"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("/", 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
}