Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add signal for example #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion example/basic_udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package main

import (
"fmt"
"log"
"os"
"os/signal"
"syscall"

"gopkg.in/mcuadros/go-syslog.v2"
)
Expand All @@ -15,14 +19,25 @@ 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)
}
}(channel)

server.Wait()

log.Println("exit")
}