-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.go
57 lines (48 loc) · 1.05 KB
/
app.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
// Golang API.
//
// Schemes: https
// Host: localhost
// BasePath: /api/v1
// Version: 0.0.1-alpha
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// swagger:meta
package main
import (
"time"
"github.com/Improwised/golang-api/cli"
"github.com/Improwised/golang-api/config"
"github.com/Improwised/golang-api/logger"
"github.com/Improwised/golang-api/routinewrapper"
"github.com/getsentry/sentry-go"
"go.uber.org/zap"
)
func main() {
// Collecting config from env or file or flag
cfg := config.GetConfig()
logger, err := logger.NewRootLogger(cfg.Debug, cfg.IsDevelopment)
if err != nil {
panic(err)
}
zap.ReplaceGlobals(logger)
// this function will logged error log in sentry
sentryLoggedFunc := func() {
err := recover()
if err != nil {
sentry.CurrentHub().Recover(err)
sentry.Flush(time.Second * 2)
}
}
// routine wrapper will handle go routine error also an log into sentry
routinewrapper.Init(sentryLoggedFunc)
defer sentryLoggedFunc()
err = cli.Init(cfg, logger)
if err != nil {
panic(err)
}
}