Open zyxkad opened 2 years ago
Yes, I need this shutdown function too.
This actually would be very handy. Love the approach and would like to see it beeing implemented.
You do not need a shutdown function to close the server. You can use the following code to achieve graceful shutdown.
// Create your own listener
l, err := net.Listen("tcp", ":7777")
if err != nil {
// handle err
}
// Start a goroutine to listen to a context and close your listener when context is done
go func() {
select {
case <-ctx.Done():
l.Close()
}
}()
if err := server.Serve(l); err != nil {
// handle err
}
Then we can shutdown it gracefully