-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
85 lines (69 loc) · 1.8 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
package main
import (
"fmt"
"log"
"net/http"
"slices"
"github.com/chris-ramon/golang-scaffolding/config"
"github.com/chris-ramon/golang-scaffolding/db"
"github.com/chris-ramon/golang-scaffolding/domain/admin"
"github.com/chris-ramon/golang-scaffolding/domain/auth"
"github.com/chris-ramon/golang-scaffolding/domain/gql"
"github.com/chris-ramon/golang-scaffolding/domain/users"
"github.com/chris-ramon/golang-scaffolding/pkg/jwt"
)
func main() {
handleErr := func(err error) {
log.Fatal(err)
}
conf := config.New()
dbConf := config.NewDBConfig()
db, err := db.New(dbConf)
if err != nil {
handleErr(err)
}
if err := db.Migrate(); err != nil {
handleErr(err)
} else {
log.Println("successfully run migrations")
}
router := http.NewServeMux()
usersRepo := users.NewRepo(db)
usersService := users.NewService(usersRepo)
usersHandlers, err := users.NewHandlers(usersService)
if err != nil {
handleErr(err)
}
usersRoutes := users.NewRoutes(usersHandlers)
jwt, err := jwt.NewJWT()
if err != nil {
handleErr(err)
}
authService, err := auth.NewService(jwt)
if err != nil {
handleErr(err)
}
authHandlers := auth.NewHandlers(authService)
authRoutes := auth.NewRoutes(authHandlers)
gqlHandlers, err := gql.NewHandlers(authService, usersService)
if err != nil {
handleErr(err)
}
gqlRoutes := gql.NewRoutes(gqlHandlers)
adminHandlers, err := admin.NewHandlers()
if err != nil {
handleErr(err)
}
adminRoutes := admin.NewRoutes(adminHandlers)
routes := slices.Concat(
authRoutes.All(),
gqlRoutes.All(),
adminRoutes.All(),
usersRoutes.All(),
)
for _, r := range routes {
router.HandleFunc(fmt.Sprintf("%s %s", r.HTTPMethod, r.Path), r.Handler)
}
log.Printf("server running on port :%s", conf.Port)
log.Println(http.ListenAndServe(fmt.Sprintf(":%s", conf.Port), router))
}