-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
40 lines (34 loc) · 897 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"ewc-backend-go/controllers"
"ewc-backend-go/database"
"ewc-backend-go/middlewares"
"github.com/gin-gonic/gin"
)
func main() {
// load the config
LoadAppConfig()
// connect the database and migrate
database.Connect(AppConfig.ConnectionString)
database.Migrate()
// Initizlize Router
router := initRouter()
router.Run(":8080")
}
func initRouter() *gin.Engine {
router := gin.Default()
api := router.Group("/api")
{
api.POST("/token", controllers.GenerateToken)
api.POST("/user/register", controllers.RegisterUser)
secured := api.Group("/secured").Use(middlewares.Auth())
{
secured.GET("/ping", controllers.Ping)
secured.GET("/users", controllers.GetUsers)
secured.GET("/users/:id", controllers.GetUserById)
secured.PUT("users/:id", controllers.UpdateUser)
secured.DELETE("users/:id", controllers.DeleteUser)
}
}
return router
}