-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
65 lines (51 loc) · 1.67 KB
/
main.go
File metadata and controls
65 lines (51 loc) · 1.67 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
59
60
61
62
63
64
65
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 {
slog.ErrorContext(ctx, "Failed to initialize configuration", slog.Any("error", err))
os.Exit(1)
}
if viper.GetBool("enableOtel") {
// Set environment variable for gRPC to skip TLS verification if configured
if viper.GetBool("insecure_skip_verify") {
os.Setenv("GRPC_GO_REQUIRE_HANDSHAKE", "false")
}
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(ctx, viper.GetString("log_level"), viper.GetString("log_format"))
err = libs.HandleSecretKey(ctx)
if err != nil {
slog.ErrorContext(ctx, "Failed to handle secret key", slog.Any("error", err))
os.Exit(1)
}
err = libs.ValidateConfiguration(ctx)
if err != nil {
slog.ErrorContext(ctx, "Configuration validation failed", slog.Any("error", err))
os.Exit(1)
}
sanitizedSettings := libs.SanitizeForLogging(viper.AllSettings())
slog.InfoContext(ctx, "Configuration loaded successfully", slog.Any("settings", sanitizedSettings))
cache.CacheInit(ctx)
libs.WebserverInit(ctx)
}