-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
63 lines (54 loc) · 1.38 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
package main
import (
"cinema/db"
"cinema/handler"
"cinema/repository/repo_impl"
"cinema/router"
"log"
"time"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
func main() {
gormDB := db.NewGormDB("127.0.0.1", "postgres", "19022003", "userlogin", 5432)
defer func() {
sqlDB, err := gormDB.DB.DB()
if err != nil {
log.Fatalf("Could not get DB: %v", err)
}
sqlDB.Close()
}()
// migrate
gormDB.Migrate()
r := gin.Default()
// CORS
r.Use(cors.New(cors.Config{
AllowOrigins: []string{"http://127.0.0.1:5500"},
AllowMethods: []string{"GET", "POST", "PUT", "DELETE"},
AllowHeaders: []string{"Content-Type", "Authorization"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
MaxAge: 12 * time.Hour,
}))
userHandler := handler.UserHandler{
UserRepo: repo_impl.NewUserRepo(gormDB.DB), // GORM
}
filmHandler := handler.FilmHandler{
FilmRepo: repo_impl.NewFilmRepoImpl(gormDB.DB), // GORM
}
scheduleHandler := handler.ScheduleHandler{
ScheduleRepo: *repo_impl.NewScheduleRepoImpl(gormDB.DB),
}
bookhingHandler := handler.BookingHandler{
BookingRepo: repo_impl.NewBookingRepo(gormDB.DB),
}
api := router.API{
Router: r,
UserHandler: userHandler,
FilmHandler: filmHandler,
ScheduleHandler: scheduleHandler,
BookingHandler: bookhingHandler,
}
api.SetupRouter()
r.Run(":3000")
}