stop: use graceful shutdown for 5s
This commit is contained in:
		
							
								
								
									
										5
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								main.go
									
									
									
									
									
								
							@ -8,6 +8,7 @@ import (
 | 
			
		||||
	"os"
 | 
			
		||||
	"os/signal"
 | 
			
		||||
	"syscall"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"git.vinchent.xyz/vinchent/go-web/framework"
 | 
			
		||||
)
 | 
			
		||||
@ -33,7 +34,9 @@ func main() {
 | 
			
		||||
	<-quit
 | 
			
		||||
	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)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user