-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
51 lines (39 loc) · 1.08 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
package main
import (
"context"
"os"
"log/slog"
"github.com/spf13/viper"
"github.com/wasilak/elastauth/cache"
"github.com/wasilak/elastauth/libs"
"github.com/wasilak/elastauth/logger"
otelgotracer "github.com/wasilak/otelgo/tracing"
)
// The main function initializes configuration, logger, secret key, cache, and web server for a Go
// application.
func main() {
ctx := context.Background()
err := libs.InitConfiguration()
if err != nil {
panic(err)
}
if viper.GetBool("enableOtel") {
otelGoTracingConfig := otelgotracer.Config{
HostMetricsEnabled: viper.GetBool("enableOtelHostMetrics"),
RuntimeMetricsEnabled: viper.GetBool("enableOtelRuntimeMetrics"),
}
_, _, err := otelgotracer.Init(ctx, otelGoTracingConfig)
if err != nil {
slog.ErrorContext(ctx, err.Error())
os.Exit(1)
}
}
logger.LoggerInit(viper.GetString("log_level"), viper.GetString("log_format"))
err = libs.HandleSecretKey(ctx)
if err != nil {
panic(err)
}
slog.DebugContext(ctx, "logger", slog.Any("setings", viper.AllSettings()))
cache.CacheInit(ctx)
libs.WebserverInit(ctx)
}