-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (44 loc) · 1.06 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
52
53
54
package main
import (
"flag"
"log"
"log/slog"
"os"
"github.com/brocode/neoweb/config"
"github.com/brocode/neoweb/server"
)
func main() {
configFile := flag.String("config-file", "config.hcl", "Config file location")
config, err := config.ParseConfig(*configFile)
if err != nil {
log.Fatalf("Failed to parse config %v", err)
}
flag.Parse()
var level slog.Level
switch config.Log.Level {
case "debug":
level = slog.LevelDebug
case "info":
level = slog.LevelInfo
case "warn":
level = slog.LevelWarn
case "error":
level = slog.LevelError
default:
log.Fatalf("unknown log level: %s", config.Log.Level)
}
var handler slog.Handler
switch config.Log.Format {
case "text":
handler = slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: level})
case "json":
handler = slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: level})
default:
log.Fatalf("unknown log format: %s", config.Log.Format)
}
logger := slog.New(handler)
slog.SetDefault(logger)
server := server.NewServer(config)
defer server.Close()
server.Start()
}