From 53ed37a21819522161ec06ae311b1433a32d144e Mon Sep 17 00:00:00 2001 From: loveuer Date: Sat, 13 Jan 2024 19:59:24 +0800 Subject: [PATCH] test: quit --- xtest/quit/main.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/xtest/quit/main.go b/xtest/quit/main.go index 4ea9671..72e6943 100644 --- a/xtest/quit/main.go +++ b/xtest/quit/main.go @@ -7,27 +7,22 @@ import ( "time" ) +var ( + app = nf.New() + quit = make(chan bool) +) + func main() { - app := nf.New() - quit := make(chan bool) app.Get("/name", handleGet) go func() { - err := app.Run(":7383") + err := app.Run(":80") log.Print("run with err=", err) - }() - - go func() { - time.Sleep(5 * time.Second) - err := app.Shutdown(context.TODO()) - log.Print("quit with err=", err) quit <- true }() <-quit - - log.Print("quited") } func handleGet(c *nf.Ctx) error { @@ -45,5 +40,13 @@ func handleGet(c *nf.Ctx) error { return nf.NewNFError(400, err.Error()) } + if req.Name == "quit" { + + go func() { + time.Sleep(2 * time.Second) + log.Print("app quit = ", app.Shutdown(context.TODO())) + }() + } + return c.JSON(nf.Map{"req_map": req}) }