api-base/router/routes/routes.go

43 lines
815 B
Go
Raw Normal View History

2020-08-03 12:19:47 +00:00
package routes
import (
2020-08-16 09:39:13 +00:00
"go-api/pkg/context"
"go-api/router/controller"
"go-api/router/middleware"
"os"
2020-08-03 12:19:47 +00:00
"github.com/gin-gonic/gin"
)
2020-08-16 09:39:13 +00:00
var patch = context.PatchContext
// New web server engine
2020-08-03 12:19:47 +00:00
func New() *gin.Engine {
e := gin.New()
e.Use(gin.Logger())
e.Use(gin.Recovery())
2020-08-16 09:39:13 +00:00
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))
}
2020-08-03 12:19:47 +00:00
return e
}
2020-08-16 09:39:13 +00:00
// SetRoute setup all routes
2020-08-03 12:19:47 +00:00
func SetRoute(e *gin.Engine) {
2020-08-16 09:39:13 +00:00
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
2020-08-03 12:19:47 +00:00
}