-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathmain.go
More file actions
91 lines (80 loc) · 2.34 KB
/
Copy pathmain.go
File metadata and controls
91 lines (80 loc) · 2.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2025 Element Creations Ltd.
// Copyright 2023 - 2025 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
// main.go: process entry point. Sets up structured logging, parses the
// environment-driven Config (see config.go), constructs a Handler (see
// handler.go), and serves it.
package main
import (
"log"
"log/slog"
"net/http"
"os"
"strings"
"github.com/SladkyCitron/slogcolor"
"github.com/livekit/protocol/auth"
"github.com/mattn/go-isatty"
)
func main() {
opts := slogcolor.DefaultOptions
opts.NoColor = !isatty.IsTerminal(os.Stderr.Fd())
logLevelString := os.Getenv("LIVEKIT_LOG_LEVEL")
switch strings.ToLower(logLevelString) {
case "debug":
opts.Level = slog.LevelDebug
case "info":
case "warn", "warning":
opts.Level = slog.LevelWarn
case "error":
opts.Level = slog.LevelError
case "":
opts.Level = slog.LevelInfo
slog.Info("log level defaulting to info")
default:
opts.Level = slog.LevelInfo
slog.Warn("Invalid log level in LIVEKIT_LOG_LEVEL, defaulting to info",
"invalidValue", logLevelString)
}
slog.SetDefault(slog.New(slogcolor.NewHandler(os.Stderr, opts)))
config, err := parseConfig()
if err != nil {
log.Fatal(err)
}
var store store
if config.RedisURL != "" {
store, err = newRedisStore(config.RedisURL)
if err != nil {
log.Fatalf("Could not connect Redis store: %v", err)
}
} else {
slog.Warn("LIVEKIT_REDIS_URL not set. Using in-memory store.")
store = nil
}
handler := NewHandler(
LiveKitAuth{
key: config.Key,
secret: config.Secret,
authProvider: auth.NewSimpleKeyProvider(config.Key, config.Secret),
lkUrl: config.LkUrl,
},
config.SkipVerifyTLS,
config.FullAccessHomeservers,
config.SanityCheckInterval,
config.CsApiUrlOverrides,
store,
)
sanityCheckIntervalDisplay := "disabled"
if config.SanityCheckInterval > 0 {
sanityCheckIntervalDisplay = config.SanityCheckInterval.String()
}
slog.Info("Starting service",
"LIVEKIT_URL", config.LkUrl,
"LIVEKIT_JWT_BIND", config.LkJwtBind,
"LIVEKIT_FULL_ACCESS_HOMESERVERS", config.FullAccessHomeservers,
"SkipVerifyTLS", config.SkipVerifyTLS,
"SanityCheckInterval", sanityCheckIntervalDisplay,
)
log.Fatal(http.ListenAndServe(config.LkJwtBind, handler.prepareMux()))
}