-
Notifications
You must be signed in to change notification settings - Fork 43
/
wire.go
105 lines (92 loc) · 2.1 KB
/
wire.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
//go:build wireinject
// +build wireinject
package main
import (
"golang-starter/infrastructures/db"
"golang-starter/infrastructures/db/transaction"
"golang-starter/infrastructures/localdb"
"golang-starter/internal/protocols/http"
httprouter "golang-starter/internal/protocols/http/router"
jwtauth "golang-starter/internal/utils/auth"
httphandler "golang-starter/src/handlers/http"
productrepo "golang-starter/src/modules/product/repositories"
productsvc "golang-starter/src/modules/product/services"
userrepo "golang-starter/src/modules/user/repositories"
usersvc "golang-starter/src/modules/user/services"
"github.com/google/wire"
)
// wiring transaction
// var transactionDB = wire.NewSet(
// transaction.NewTransaction,
// )
// wiring jwt auth
var jwtAuth = wire.NewSet(
jwtauth.NewJwt,
wire.Bind(
new(jwtauth.JwtToken),
new(*jwtauth.JwtTokenImpl),
),
)
// Wiring for domain
// product
var productRepo = wire.NewSet(
productrepo.NewRepository,
wire.Bind(
new(productrepo.Repositories),
new(*productrepo.RepositoriesImpl),
),
)
var productSvc = wire.NewSet(
productsvc.NewProductService,
wire.Bind(
new(productsvc.ProductService),
new(*productsvc.ProductServiceImpl),
),
)
// user
var userMysqlRepo = wire.NewSet(
userrepo.NewRepository,
wire.Bind(
new(userrepo.Repositories),
new(*userrepo.RepositoriesImpl),
),
)
var userScribleRepo = wire.NewSet(
userrepo.NewUserScribleRepository,
wire.Bind(
new(userrepo.UserScribleRepository),
new(*userrepo.UserScribleRepositoryImpl),
),
)
var userSvc = wire.NewSet(
usersvc.NewUserService,
wire.Bind(
new(usersvc.UserService),
new(*usersvc.UserServiceImpl),
),
)
// Wiring for http protocol
var httpHandler = wire.NewSet(
httphandler.NewHttpHandler,
)
// Wiring protocol routing
var httpRouter = wire.NewSet(
httprouter.NewHttpRoute,
)
func InitHttpProtocol() *http.HttpImpl {
wire.Build(
db.NewMysqlClient,
localdb.NewScribleClient,
transaction.NewTransaction,
productRepo,
userMysqlRepo,
userScribleRepo,
jwtAuth,
productSvc,
userSvc,
httpHandler,
httpRouter,
http.NewHttpProtocol,
)
return &http.HttpImpl{}
}