Compare commits
2 Commits
0786a97a77
...
c0fea38790
Author | SHA1 | Date | |
---|---|---|---|
|
c0fea38790 | ||
|
b98513ad36 |
@ -58,6 +58,7 @@ func FooControllerHandler(ctx *framework.Context) error {
|
||||
}
|
||||
|
||||
func UserLoginController(ctx *framework.Context) error {
|
||||
time.Sleep(10 * time.Second)
|
||||
ctx.WriteJSON(http.StatusOK, "ok")
|
||||
return nil
|
||||
}
|
||||
|
22
main.go
22
main.go
@ -1,8 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"git.vinchent.xyz/vinchent/go-web/framework"
|
||||
)
|
||||
@ -15,7 +20,20 @@ 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")
|
||||
|
||||
if err := server.Shutdown(context.Background()); err != nil {
|
||||
log.Fatal("server shutdown: ", err)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user