-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
54 lines (41 loc) · 990 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
package main
import (
"context"
"os"
"github.com/Rocket-Rescue-Node/rescue-proxy/config"
"go.uber.org/zap"
)
func loop(signalChan chan bool, errs chan error) error {
for {
select {
case <-signalChan:
return nil
case err := <-errs:
return err
}
}
}
func main() {
// Initialize config
config := config.InitFlags()
// Create the service
service := NewService(config)
logger := initLogger(config)
defer func() {
logger.Info("rescue-proxy shutdown completed, flushing logs")
_ = logger.Sync()
}()
service.Logger = logger
// Trap signals
logger.Debug("Trapping SIGTERM and SIGINT")
signalChan := handleSignals(os.Interrupt)
errs := service.Run(context.Background())
if err := loop(signalChan, errs); err != nil {
logger.Panic("error running service", zap.Error(err))
}
// Shut down gracefully
logger.Info("Received signal, shutting down")
if err := service.Stop(); err != nil {
logger.Panic("error stopping service", zap.Error(err))
}
}