-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
98 lines (80 loc) · 3.46 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
assignmentsRouting "github.com/schiller-sql/littSQL/assignments/delivery/routing"
assignmentsR "github.com/schiller-sql/littSQL/assignments/repository"
assignmentsU "github.com/schiller-sql/littSQL/assignments/usecase"
"net/http"
"github.com/gin-gonic/gin"
authM "github.com/schiller-sql/littSQL/auth/delivery/middleware"
authRouting "github.com/schiller-sql/littSQL/auth/delivery/routing"
authR "github.com/schiller-sql/littSQL/auth/repository"
authU "github.com/schiller-sql/littSQL/auth/usecase"
"github.com/schiller-sql/littSQL/config"
coursesRouting "github.com/schiller-sql/littSQL/courses/delivery/routing"
coursesR "github.com/schiller-sql/littSQL/courses/repository"
coursesU "github.com/schiller-sql/littSQL/courses/usecase"
databaseTemplatesRouting "github.com/schiller-sql/littSQL/database_templates/delivery/routing"
databaseTemplatesR "github.com/schiller-sql/littSQL/database_templates/repository"
databaseTemplatesU "github.com/schiller-sql/littSQL/database_templates/usecase"
participantsRouting "github.com/schiller-sql/littSQL/participants/delivery/routing"
participantsR "github.com/schiller-sql/littSQL/participants/repository"
participantsU "github.com/schiller-sql/littSQL/participants/usecase"
projectsRouting "github.com/schiller-sql/littSQL/projects/delivery/routing"
projectsR "github.com/schiller-sql/littSQL/projects/repository"
projectsU "github.com/schiller-sql/littSQL/projects/usecase"
"github.com/spf13/viper"
)
//func ErrorHandler(c *gin.Context) {
// c.Next()
//
// for _, err := range c.Errors {
// statusCode := c.Writer.Status()
// c.JSON(statusCode, gin.H{"error": err.Error()})
// break
// }
//}
func getRouter() *gin.Engine {
mode := viper.Get("MODE").(string)
gin.SetMode(mode)
router := gin.Default()
//router.Use(ErrorHandler)
// setup static files for svelte
// TODO: use gzip
router.NoRoute(gin.WrapH(http.FileServer(gin.Dir("../frontend/public", false))))
err := router.SetTrustedProxies(nil)
if err != nil {
panic(err)
}
return router
}
func main() {
config.InitConfigFile()
db := config.InitPostgresDB()
r := getRouter()
{
g := r.Group("/api")
authRepo := authR.NewRepository(db, viper.Get("BCRYPT_COST").(int))
authUsecase := authU.NewUsecase(authRepo)
authMiddleware := authM.NewAuthMiddleware(authUsecase)
authRouting.ConfigureHandler(g, authMiddleware, authUsecase)
databaseTemplatesRepo := databaseTemplatesR.NewRepository(db)
databaseTemplatesUsecase := databaseTemplatesU.NewUsecase(databaseTemplatesRepo)
databaseTemplatesRouting.ConfigureHandler(g, authMiddleware, databaseTemplatesUsecase)
projectsRepo := projectsR.NewRepository(db)
projectsUsecase := projectsU.NewUsecase(projectsRepo)
projectsRouting.ConfigureHandler(g, authMiddleware, projectsUsecase)
coursesRepo := coursesR.NewRepository(db)
coursesUsecase := coursesU.NewUsecase(coursesRepo)
courseGroup := coursesRouting.ConfigureHandler(g, authMiddleware, coursesUsecase)
participantsRepo := participantsR.NewRepository(db)
participantsUsecase := participantsU.NewUsecase(participantsRepo, coursesRepo)
participantsRouting.ConfigureHandler(courseGroup, authMiddleware, participantsUsecase)
assignmentsRepo := assignmentsR.NewRepository(db)
assignmentsUsecase := assignmentsU.NewUsecase(assignmentsRepo, coursesRepo, projectsRepo)
assignmentsRouting.ConfigureHandler(courseGroup, authMiddleware, assignmentsUsecase)
}
err := r.Run(":" + (viper.Get("PORT").(string)))
if err != nil {
panic(err)
}
}