2024-08-24 01:16:10 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-08-25 01:43:44 +03:00
|
|
|
"context"
|
2024-08-24 01:16:10 +03:00
|
|
|
"fmt"
|
|
|
|
"log"
|
2024-08-24 21:26:49 +03:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
2024-08-26 19:10:40 +03:00
|
|
|
"time"
|
2024-08-24 01:16:10 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2024-08-26 19:10:40 +03:00
|
|
|
app, err := New(Config{
|
|
|
|
MinimalTTL: time.Hour,
|
2024-08-30 04:15:38 +03:00
|
|
|
ChainPostfix: "KVAS2_",
|
2024-08-30 04:40:46 +03:00
|
|
|
IpSetPostfix: "kvas2_",
|
2024-08-26 19:10:40 +03:00
|
|
|
TargetDNSServerAddress: "127.0.0.1:53",
|
|
|
|
ListenPort: 7548,
|
|
|
|
})
|
2024-08-25 01:43:44 +03:00
|
|
|
if err != nil {
|
2024-08-26 19:10:40 +03:00
|
|
|
log.Fatalf("failed to initialize application: %v", err)
|
2024-08-24 01:16:10 +03:00
|
|
|
}
|
2024-08-24 21:26:49 +03:00
|
|
|
|
2024-08-25 01:43:44 +03:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
|
2024-08-26 19:10:40 +03:00
|
|
|
appErrsChan := make(chan []error)
|
2024-08-24 21:26:49 +03:00
|
|
|
go func() {
|
2024-08-26 19:10:40 +03:00
|
|
|
errs := app.Listen(ctx)
|
|
|
|
appErrsChan <- errs
|
2024-08-24 21:26:49 +03:00
|
|
|
|
2024-08-26 19:10:40 +03:00
|
|
|
}()
|
2024-08-25 01:43:44 +03:00
|
|
|
|
2024-08-26 19:10:40 +03:00
|
|
|
fmt.Println("Started service...")
|
2024-08-25 01:43:44 +03:00
|
|
|
|
2024-08-24 21:26:49 +03:00
|
|
|
c := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
2024-08-26 19:10:40 +03:00
|
|
|
case appErrs, _ := <-appErrsChan:
|
|
|
|
for _, err := range appErrs {
|
|
|
|
// TODO: Error log level
|
|
|
|
log.Printf("failed to start application: %v", err)
|
|
|
|
}
|
|
|
|
return
|
2024-08-24 21:26:49 +03:00
|
|
|
case <-c:
|
2024-08-25 01:46:47 +03:00
|
|
|
fmt.Println("Graceful shutdown...")
|
2024-08-25 01:43:44 +03:00
|
|
|
cancel()
|
2024-08-24 21:26:49 +03:00
|
|
|
}
|
2024-08-24 01:16:10 +03:00
|
|
|
}
|
|
|
|
}
|