stop: catch signals

This commit is contained in:
Muyao CHEN 2024-09-26 22:27:26 +02:00
parent 0786a97a77
commit b98513ad36

20
main.go
View File

@ -1,8 +1,11 @@
package main
import (
"log"
"fmt"
"net/http"
"os"
"os/signal"
"syscall"
"git.vinchent.xyz/vinchent/go-web/framework"
)
@ -15,7 +18,16 @@ func main() {
Handler: core,
}
if err := server.ListenAndServe(); err != nil {
log.Panic(err)
}
go func() {
server.ListenAndServe()
}()
// create quit channel
quit := make(chan os.Signal, 1)
// set notifier
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
<-quit
fmt.Println("YOLO")
}