-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathmain.go
More file actions
36 lines (30 loc) · 711 Bytes
/
Copy pathmain.go
File metadata and controls
36 lines (30 loc) · 711 Bytes
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
package main
import (
"context"
"log/slog"
"os"
"os/signal"
"syscall"
"github.com/charmbracelet/log"
"github.com/stupside/castor/cmd"
)
func main() {
slog.SetDefault(slog.New(
log.NewWithOptions(os.Stderr, log.Options{
ReportTimestamp: true,
TimeFormat: "15:04:05.000",
Level: log.InfoLevel,
}),
))
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
root := cmd.Root()
if err := root.Run(ctx, os.Args); err != nil {
if cause := context.Cause(ctx); cause != nil {
slog.InfoContext(ctx, "shutting down", "cause", cause)
return
}
slog.ErrorContext(ctx, "application error", "error", err)
os.Exit(1)
}
}