-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
77 lines (65 loc) · 1.67 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
package main
import (
"claudinary-cdn-api/config"
"claudinary-cdn-api/controllers"
"claudinary-cdn-api/migration"
"claudinary-cdn-api/repository"
"claudinary-cdn-api/router"
"flag"
"log"
)
func main() {
loadConfig, _ := config.LoadConfig()
db, err := config.StartDB(&loadConfig)
if err != nil {
log.Fatalf("🧊 Tidak bisa terhubung ke database.")
}
cld, err := config.ConnectCld(&loadConfig)
if err != nil {
log.Fatalf("🧊 Tidak bisa terhubung ke cloudinary.")
}
// Definisikan flag --migrate
input := flag.Bool("migrate", false, "Run migration scripts")
// Parsing flag
flag.Parse()
if *input {
//Migration
err = migration.MigrationDB(db)
if err != nil {
log.Fatal("🧊 Tidak bisa melakukan migrasi database. ", err)
}
return
}
//init repository
bucketRepository := repository.NewBucketRepository(db)
pathRepository := repository.NewPathRepository(db)
fileRepository := repository.NewFileRepository(db)
cloudinaryRepository := repository.NewCloudinaryRepository(cld)
//init controller
bucketController := controllers.NewBucketController(bucketRepository)
pathController := controllers.NewPathController(
bucketRepository,
pathRepository,
)
fileController := controllers.NewFileController(
bucketRepository,
pathRepository,
fileRepository,
)
uploaderController := controllers.NewUploaderController(
bucketRepository,
pathRepository,
fileRepository,
cloudinaryRepository,
)
//init router
r := router.NewRouter(
bucketController,
pathController,
fileController,
uploaderController,
)
log.Println("🧊 ENV: ", loadConfig.ENV)
log.Println("🧊 Menjalankan di port :", loadConfig.PORT)
r.Run(":" + loadConfig.PORT)
}