feat: if report http server close err as run err

This commit is contained in:
loveuer
2024-01-13 18:54:23 +08:00
parent f938487884
commit 286f010346
4 changed files with 64 additions and 6 deletions

49
xtest/quit/main.go Normal file
View File

@ -0,0 +1,49 @@
package main
import (
"context"
"github.com/loveuer/nf"
"log"
"time"
)
func main() {
app := nf.New()
quit := make(chan bool)
app.Get("/name", handleGet)
go func() {
err := app.Run(":7383")
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 {
type Req struct {
Name string `query:"name"`
Addr []string `query:"addr"`
}
var (
err error
req = Req{}
)
if err = c.QueryParser(&req); err != nil {
return nf.NewNFError(400, err.Error())
}
return c.JSON(nf.Map{"req_map": req})
}