stop: catch signals
This commit is contained in:
parent
0786a97a77
commit
b98513ad36
20
main.go
20
main.go
@ -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")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user