-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
52 lines (43 loc) · 1.49 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
package main
import (
"log"
authapp "github.com/kasbuunk/microservice/auth/core"
"github.com/kasbuunk/microservice/auth/port/repository/user"
"github.com/kasbuunk/microservice/config"
emailapp "github.com/kasbuunk/microservice/email/core"
"github.com/kasbuunk/microservice/email/port/email"
"github.com/kasbuunk/microservice/eventbus/localbus"
"github.com/kasbuunk/microservice/internal/storage"
"github.com/kasbuunk/microservice/transport/eventhandler"
"github.com/kasbuunk/microservice/transport/gql"
)
func main() {
conf, err := config.New()
if err != nil {
log.Fatalf("Loading environment configuration failed: %v", err)
}
db, err := storage.Connect(conf.DB)
if err != nil {
log.Fatalf("Connection to storage failed: %v", err)
}
// Initialise adapters.
userRepo := userrepo.New(db)
emailClient := emailclient.New(conf.Postmark)
eventBus := localbus.New([]string{
"AUTH",
"EMAIL",
})
// Initialise Apps that implement all core domain logic, injecting dependencies.
authApp := authapp.New(eventBus, userRepo)
emailApp := emailapp.New(eventBus, emailClient)
// Initialise sources of input: event handlers.
go eventhandler.NewAuthEventHandler(authApp, eventBus).Handle()
go eventhandler.NewEmailEventHandler(emailApp, eventBus).Handle()
// Initialise Graphql http server.
authServer := gql.New(authApp, conf.GQLServer.Endpoint)
// Start process that serves GraphQL requests.
err = authServer.Serve(conf.GQLServer.Port)
if err != nil {
log.Fatalf("Serving failed: %v", err)
}
}