-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (45 loc) · 1.03 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 (
"context"
"github.com/rs/zerolog"
"os"
"os/signal"
"syscall"
"time"
"github.com/rs/zerolog/log"
)
func main() {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
app, err := New(Config{
MinimalTTL: time.Hour,
ChainPrefix: "KVAS2_",
IpSetPrefix: "kvas2_",
LinkName: "br0",
TargetDNSServerAddress: "127.0.0.1:53",
ListenPort: 7548,
})
if err != nil {
log.Fatal().Err(err).Msg("failed to initialize application")
}
ctx, cancel := context.WithCancel(context.Background())
appResult := make(chan error)
go func() {
appResult <- app.Listen(ctx)
}()
log.Info().Msg("starting service")
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
for {
select {
case err, _ := <-appResult:
if err != nil {
log.Error().Err(err).Msg("failed to start application")
}
log.Info().Msg("exiting application")
return
case <-c:
log.Info().Msg("shutting down service")
cancel()
}
}
}