-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
58 lines (47 loc) · 1.34 KB
/
main.go
File metadata and controls
58 lines (47 loc) · 1.34 KB
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
package main
import (
"log/slog"
"github.com/Stogas/feedback-api/internal/config"
"go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
)
func init() {
// loads values from .env into the system
if err := godotenv.Load(); err != nil {
slog.Info("No .env file found")
}
}
func main() {
conf := config.New()
gin.SetMode(gin.ReleaseMode)
var globalMiddlewares []gin.HandlerFunc
// tracing
if conf.Tracing.Enabled {
tracerClose, b3 := initTracer(conf.Tracing)
defer tracerClose()
globalMiddlewares = append(globalMiddlewares, otelgin.Middleware("feedback-api", otelgin.WithPropagators(b3)))
}
// logging
initLogger(conf.Logs)
var l gin.HandlerFunc
if conf.Logs.JSON {
if conf.Tracing.Enabled {
l = traceLogMiddleware()
} else {
l = regularLogMiddleware()
}
} else {
l = gin.Logger()
}
globalMiddlewares = append(globalMiddlewares, l)
// database
db := initDB(conf.Database, conf.Tracing.Enabled, conf.IssueTypes)
dbMiddleware := createDBMiddleware(db)
// metrics
rMetrics, p := initMetrics(globalMiddlewares)
// start metrics listener in the background
go startMetrics(rMetrics, conf.Metrics)
globalMiddlewares = append(globalMiddlewares, p.Instrument(), metricsMiddleware(p))
startAPI(conf.API, globalMiddlewares, dbMiddleware)
}