Last active
September 6, 2019 17:04
-
-
Save kanzitelli/082a9fb670361eed9d26a1747832cb79 to your computer and use it in GitHub Desktop.
server/routers.go #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package server | |
import ( | |
"github.com/gin-contrib/cors" | |
"github.com/gin-gonic/gin" | |
) | |
// NewRouter <function> | |
// is used to create a GIN engine instance where all controller and routes will be placed | |
func NewRouter() *gin.Engine { | |
var envVars = utils.GetEnvVars() | |
if envVars.DebugMode { | |
gin.SetMode(gin.DebugMode) | |
} else { | |
gin.SetMode(gin.ReleaseMode) | |
} | |
router := gin.New() | |
// middlewares | |
router.Use(gin.Recovery()) | |
router.Use(gin.Logger()) | |
router.Use(cors.Default()) | |
// static files serving | |
router.Static("/images", "./images") | |
// endpoints | |
v1 := router.Group("v1") | |
{ | |
news := v1.Group("news") | |
{ | |
nc := controllers.NewsController{} | |
news.GET("/", nc.Get) | |
news.GET("/sources", nc.GetSources) | |
news.GET("/types", nc.GetTypes) | |
} | |
} | |
return router | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment