52 lines
892 B
Go
Raw Normal View History

package main
import (
2024-08-25 01:43:44 +03:00
"context"
"fmt"
"log"
2024-08-24 21:26:49 +03:00
"os"
"os/signal"
"syscall"
2024-08-26 19:10:40 +03:00
"time"
)
func main() {
2024-08-26 19:10:40 +03:00
app, err := New(Config{
MinimalTTL: time.Hour,
ChainPostfix: "KVAS2",
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 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
}
}
}