-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
63 lines (46 loc) · 1.49 KB
/
main.go
File metadata and controls
63 lines (46 loc) · 1.49 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
package main
import (
"log/slog"
"strings"
"github.com/Mtze/CI-Benchmarker/persister"
"github.com/Mtze/CI-Benchmarker/shared/config"
docs "github.com/Mtze/CI-Benchmarker/docs"
)
// @title CI-Benchmarker API
// @version 1.0
// @description Benchmark system collecting CI latency, build time and metrics.
// @termsOfService https://github.com/Mtze/CI-Benchmarker
// @contact.name Shuaiwei Yu
// @contact.url https://github.com/Mtze
// @contact.email yu.shuaiwei@tum.de
// @license.name MIT
// @license.url https://opensource.org/licenses/MIT
// @host localhost:8080
// @BasePath /v1
// @schemes http https
// Persister handles to store the job results in the database
var p persister.Persister
func main() {
// Set the log level to debug if the DEBUG environment variable is set to true
if is_debug := config.GetEnv("DEBUG"); is_debug == "true" {
slog.Warn("DEBUG MODE ENABLED")
slog.SetLogLoggerLevel(slog.LevelDebug)
}
cfg := config.Load()
slog.Debug("Creating DB persister")
p = persister.NewDBPersister()
addr := cfg.ServerAddress
if addr == "" {
addr = ":8080"
} else if !strings.HasPrefix(addr, ":") {
addr = ":" + addr
}
slog.Info("Starting server", slog.String("address", addr))
port := strings.TrimPrefix(addr, ":")
docs.SwaggerInfo.Host = "localhost:" + port
docs.SwaggerInfo.Schemes = []string{"http"}
r := startRouter()
if err := r.Run(addr); err != nil {
slog.Error("Failed to start server", slog.Any("error", err))
}
}