From 5a3e42e0fe175a27e58c77b7716491c77b15035b Mon Sep 17 00:00:00 2001 From: rfyiamcool Date: Mon, 21 Aug 2023 22:59:26 +0800 Subject: [PATCH] fix: add signal for example Signed-off-by: rfyiamcool --- example/basic_udp.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/example/basic_udp.go b/example/basic_udp.go index 90a1f7b..930e19a 100644 --- a/example/basic_udp.go +++ b/example/basic_udp.go @@ -2,6 +2,10 @@ package main import ( "fmt" + "log" + "os" + "os/signal" + "syscall" "gopkg.in/mcuadros/go-syslog.v2" ) @@ -15,9 +19,18 @@ func main() { server.SetHandler(handler) server.ListenUDP("0.0.0.0:514") server.ListenTCP("0.0.0.0:514") - server.Boot() + log.Println("start") + + go func() { + sigch := make(chan os.Signal, 1) + signal.Notify(sigch, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM) + <-sigch + + server.Kill() + }() + go func(channel syslog.LogPartsChannel) { for logParts := range channel { fmt.Println(logParts) @@ -25,4 +38,6 @@ func main() { }(channel) server.Wait() + + log.Println("exit") }