-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
57 lines (47 loc) · 1005 Bytes
/
main.go
File metadata and controls
57 lines (47 loc) · 1005 Bytes
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
package main
import (
"github.com/EventStore/EventStore-Client-Go/esdb"
ginzap "github.com/gin-contrib/zap"
"github.com/gin-gonic/gin"
"github.com/tyronegroves/cqrs-sample-api/config"
"github.com/tyronegroves/cqrs-sample-api/server"
"go.uber.org/zap"
"log"
"time"
)
func main() {
if err := run(); err != nil {
log.Fatal(err)
}
}
func run() error {
cfg, err := config.LoadConfiguration()
if err != nil {
return err
}
l, err := zap.NewDevelopment()
if err != nil {
return err
}
settings, err := esdb.ParseConnectionString(cfg.EventStoreDb.Url)
if err != nil {
return err
}
db, err := esdb.NewClient(settings)
if err != nil {
return err
}
defer db.Close()
r := gin.New()
r.Use(ginzap.Ginzap(l, time.RFC3339, true))
r.Use(ginzap.RecoveryWithZap(l, true))
if err := r.SetTrustedProxies(cfg.TrustedProxies); err != nil {
return err
}
s := server.New(l, r, db)
s.LoadRoutes()
if err := r.Run(cfg.LocalAddresses...); err != nil {
return err
}
return nil
}