-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
127 lines (111 loc) · 2.82 KB
/
server.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package main
import (
"clean-arch-2/alamat"
"clean-arch-2/config"
"clean-arch-2/daerah"
"clean-arch-2/handlers"
"clean-arch-2/kategori"
"clean-arch-2/keranjang"
"clean-arch-2/middlewares"
"clean-arch-2/pesanan"
"clean-arch-2/produk"
"clean-arch-2/role"
"clean-arch-2/user"
// "github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"os"
)
func main() {
//init database
db, err := config.InitDB()
if err != nil {
panic(err)
}
//load .env server
config.Init(".server")
// engine := gin.Default()
// engine.Static("/public/images/products", "./public/images/products")
//init router
engine := gin.Default()
engine.Use(middlewares.CorsMiddleware())
router := config.NewRouter(engine)
router.Gin.Static("/public/images/users", "./public/images/users")
router.Gin.Static("/public/images/products", "./public/images/products")
//init middleware
middleware := middlewares.Middleware{}
// roleMiddleware := middlewares.RoleMiddleware{}
//init role
roleRepo := role.NewRoleRepository(db)
roleService := role.NewRoleService(roleRepo)
//init auth
userRepo := user.NewUserRepository(db)
userService := user.NewUserService(userRepo)
authHandler := handlers.NewAuthHandler(router, userService, roleService)
//init daerah
daerahRepo := daerah.NewDaerahRepository(db)
daerahService := daerah.NewDaerahService(daerahRepo)
daerahHandler := handlers.NewDaerahHandler(
router,
daerahService,
middleware,
)
//init alamat
alamatRepo := alamat.NewAlamatRepository(db)
alamatService := alamat.NewAlamatService(alamatRepo)
alamatHandler := handlers.NewAlamatHandler(
router,
alamatService,
roleService,
middleware,
)
//init kategori
kategoriRepo := kategori.NewKategoriRepository(db)
kategoriService := kategori.NewKategoriService(kategoriRepo)
kategoriHandler := handlers.NewKategoriHandler(
router,
kategoriService,
middleware,
)
//init produk
produkRepo := produk.NewProdukRepository(db)
produkService := produk.NewProdukService(produkRepo)
produkHandler := handlers.NewProdukHandler(
router,
produkService,
kategoriService,
middleware,
)
//init keranjang
keranjangRepo := keranjang.NewKeranjangRepository(db)
keranjangService := keranjang.NewKeranjangService(keranjangRepo)
keranjangHandler := handlers.NewKeranjangHandler(
router,
keranjangService,
userService,
alamatService,
produkService,
middleware,
)
//init pesanan
pesananRepo := pesanan.NewPesananRepository(db)
pesananService := pesanan.NewPesananService(pesananRepo)
pesananHandler := handlers.NewPesananHandler(
router,
pesananService,
keranjangService,
alamatService,
produkService,
middleware,
)
//setup router
handlers.NewHandlers(
authHandler,
daerahHandler,
alamatHandler,
kategoriHandler,
produkHandler,
keranjangHandler,
pesananHandler,
).Setup()
router.Gin.Run(":" + os.Getenv("PORT"))
}