stop: use graceful shutdown

This commit is contained in:
Muyao CHEN 2024-09-26 22:58:55 +02:00
parent b98513ad36
commit c0fea38790
2 changed files with 7 additions and 0 deletions

View File

@ -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
}

View File

@ -1,7 +1,9 @@
package main
import (
"context"
"fmt"
"log"
"net/http"
"os"
"os/signal"
@ -30,4 +32,8 @@ func main() {
<-quit
fmt.Println("YOLO")
if err := server.Shutdown(context.Background()); err != nil {
log.Fatal("server shutdown: ", err)
}
}