-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
85 lines (65 loc) · 2.45 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"
"github.com/gorilla/context"
"github.com/janicduplessis/projectgo/ct/config"
"github.com/janicduplessis/projectgo/ct/infrastructure"
"github.com/janicduplessis/projectgo/ct/interfaces"
"github.com/janicduplessis/projectgo/ct/usecases"
)
func main() {
log.SetFlags(log.Lshortfile)
//Console logger
logger := new(infrastructure.LoggerHandler)
// Crypto handler
crypto := new(infrastructure.CryptoHandler)
// Base webservice handler
webservice := infrastructure.NewWebserviceHandler(logger)
// Base websocket handler
websocket := infrastructure.NewWebsocketHandler(logger)
imageUtils := new(infrastructure.ImageUtilsHandler)
var fileStore interfaces.FileStore
if config.UseS3 {
fileStoreHandler := new(infrastructure.S3FileStorageHandler)
fileStoreHandler.Init()
fileStore = fileStoreHandler
} else {
fileStore = new(infrastructure.LocalFileStoreHandler)
}
oauth2 := new(infrastructure.OAuth2Handler)
oauth2.Init()
// Database
dbConfig := infrastructure.MySqlDbConfig{
User: config.DbUser,
Password: config.DbPassword,
Name: config.DbName,
Url: config.DbUrl,
Port: config.DbPort,
}
dbHandler := infrastructure.NewMySqlHandler(dbConfig)
// Database handlers for each repo
handlers := make(map[string]interfaces.DbHandler)
handlers["DbInitializerRepo"] = dbHandler
handlers["DbClientRepo"] = dbHandler
handlers["DbUserRepo"] = dbHandler
handlers["DbMessageRepo"] = dbHandler
handlers["DbChannelRepo"] = dbHandler
// Initialize the database
dbInit := interfaces.NewDbInitializerRepo(handlers)
dbInit.Init()
//Repos
clientRepo := interfaces.NewDbClientRepo(handlers)
// Interactors
authInteractor := usecases.NewAuthentificationInteractor(interfaces.NewDbUserRepo(handlers), crypto, logger)
chatInteractor := usecases.NewChatInteractor(interfaces.NewSingletonServerRepo(handlers), interfaces.NewDbChannelRepo(handlers),
interfaces.NewDbMessageRepo(handlers), clientRepo, logger)
homeInteractor := usecases.NewHomeInteractor(clientRepo, logger)
// Webservices
interfaces.NewAuthentificationWebservice(webservice, oauth2, authInteractor, chatInteractor)
interfaces.NewChatWebservice(webservice, websocket, chatInteractor)
interfaces.NewHomeWebservice(webservice, homeInteractor, imageUtils, fileStore)
http.Handle("/", http.FileServer(http.Dir("web")))
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", config.SitePort), context.ClearHandler(http.DefaultServeMux)))
}