-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
63 lines (51 loc) · 1.42 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 (
"net/http"
"github.com/dungvan/soccer-social-network-api/infrastructure"
"github.com/dungvan/soccer-social-network-api/router"
mMiddleware "github.com/dungvan/soccer-social-network-api/shared/middleware"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
)
func main() {
// start internal server
go startInt()
// start external server
startExt()
}
func startExt() {
// sql new.
sqlHandler := infrastructure.NewSQL()
// s3 new.
s3Handler := infrastructure.NewS3()
// cache new.
cacheHandler := infrastructure.NewCache()
// logger new.
loggerHandler := infrastructure.NewLogger()
// translation new.
translationHandler := infrastructure.NewTranslation()
mux := chi.NewRouter()
r := &router.Router{
Mux: mux,
SQLHandler: sqlHandler,
S3Handler: s3Handler,
CacheHandler: cacheHandler,
LoggerHandler: loggerHandler,
TranslationHandler: translationHandler,
}
r.InitializeRouter()
r.SetupHandler()
// after process
defer infrastructure.CloseLogger(r.LoggerHandler.Logfile)
defer infrastructure.CloseRedis(r.CacheHandler.Conn)
_ = http.ListenAndServe(":8080", mux)
}
func startInt() {
mux := chi.NewRouter()
logger := infrastructure.NewLogger()
mux.Use(mMiddleware.Logger(logger))
defer infrastructure.CloseLogger(logger.Logfile)
// profile
mux.Mount("/debug", middleware.Profiler())
_ = http.ListenAndServe(":18080", mux)
}