-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (52 loc) · 1.31 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"log"
"os"
"recipe_api/src/common/db"
"recipe_api/src/controller"
)
func main() {
if err := godotenv.Load(); err != nil {
log.Panic("Error loading .env file")
}
if err := db.Open(); err != nil {
log.Panic("Error cannot connect to database")
}
if err := db.Migrate(); err != nil {
log.Panic(err.Error())
}
router := gin.Default()
userController := controller.InitUserController()
roleController := controller.InitRoleController()
postController := controller.InitPostController()
categoryController := controller.InitCategoryController()
api := router.Group("/api/v1")
{
user := api.Group("/users")
{
user.GET("/", userController.GetUsers)
user.POST("/", userController.CreateUser)
user.GET("/:userID", userController.GetUserByID)
user.PUT("/:userID", userController.UpdateUser)
}
role := api.Group("/roles")
{
role.GET("/", roleController.GetRoles)
}
post := api.Group("/posts")
{
post.GET("/", postController.GetPosts)
post.GET("/:postID", postController.GetPostByID)
}
category := api.Group("/categories")
{
category.GET("/", categoryController.GetCategories)
}
}
if err := router.Run(fmt.Sprintf(":%s", os.Getenv("APP_PORT"))); err != nil {
log.Panic(err.Error())
}
}