stop: use graceful shutdown for 5s

This commit is contained in:
Muyao CHEN 2024-09-26 23:05:05 +02:00
parent c0fea38790
commit c5ab1debdb

View File

@ -8,6 +8,7 @@ import (
"os" "os"
"os/signal" "os/signal"
"syscall" "syscall"
"time"
"git.vinchent.xyz/vinchent/go-web/framework" "git.vinchent.xyz/vinchent/go-web/framework"
) )
@ -33,7 +34,9 @@ func main() {
<-quit <-quit
fmt.Println("YOLO") fmt.Println("YOLO")
if err := server.Shutdown(context.Background()); err != nil { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := server.Shutdown(ctx); err != nil {
log.Fatal("server shutdown: ", err) log.Fatal("server shutdown: ", err)
} }
} }