-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
47 lines (39 loc) · 922 Bytes
/
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
// Package main provides the entrypoint for mcgen.
package main
import (
"log/slog"
"os"
"github.com/menzerath/mcgen/generator"
"github.com/menzerath/mcgen/metrics"
"github.com/menzerath/mcgen/web"
)
var (
commitRef string
commitHash string
)
func main() {
initLogging()
slog.Info("starting mcgen", slog.Group("build", "ref", commitRef, "hash", commitHash))
go metrics.ExposeMetrics()
gen, err := generator.New()
if err != nil {
slog.Error("initializing generator", "error", err)
os.Exit(1)
}
webAPI := web.New(gen)
webAPI.StartWebAPI()
}
func initLogging() {
var handler slog.Handler
if os.Getenv("MODE") == "production" {
handler = slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{
Level: slog.LevelInfo,
})
} else {
handler = slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
AddSource: true,
Level: slog.LevelDebug,
})
}
slog.SetDefault(slog.New(handler))
}