-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
56 lines (50 loc) · 949 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
48
49
50
51
52
53
54
55
56
package main
import (
"context"
"github.com/charmbracelet/log"
"github.com/go-rod/rod-mcp/types"
"os"
"os/signal"
"syscall"
)
func main() {
subCfg, err := RunCmd()
if err != nil {
log.Error(err)
return
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cfg, err := types.LoadConfig(subCfg.ConfigPath)
if err != nil {
log.Errorf("Load config error: %s", err)
return
}
// init logger
types.InitLogger(cfg.LoggerConfig)
if subCfg.Headless {
cfg.Headless = true
}
runner := NewRunner(ctx, *cfg)
go func() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL)
defer signal.Stop(c)
for {
select {
case <-c:
log.Info("Received signal, exiting...")
cancel()
return
}
}
}()
runner.Run()
defer func() {
err := runner.Close()
if err != nil {
log.Errorf("Server close error: %s", err)
}
}()
return
}