stop: catch signals
This commit is contained in:
parent
0786a97a77
commit
b98513ad36
20
main.go
20
main.go
@ -1,8 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"git.vinchent.xyz/vinchent/go-web/framework"
|
"git.vinchent.xyz/vinchent/go-web/framework"
|
||||||
)
|
)
|
||||||
@ -15,7 +18,16 @@ func main() {
|
|||||||
Handler: core,
|
Handler: core,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := server.ListenAndServe(); err != nil {
|
go func() {
|
||||||
log.Panic(err)
|
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