fix: middleware not work

This commit is contained in:
loveuer
2024-02-19 17:08:13 +08:00
parent de3ce47671
commit 137d4ee5c8
3 changed files with 13 additions and 5 deletions

View File

@ -6,12 +6,15 @@ import (
)
func main() {
app := nf.New()
app := nf.New(nf.Config{DisableLogger: false})
app.Use(ml())
app.Get("/hello", func(c *nf.Ctx) error {
return c.SendString("world")
})
app.Get("/panic", func(c *nf.Ctx) error {
panic("panic")
})
app.Use(ml())
log.Fatal(app.Run(":7777"))
}
@ -19,6 +22,9 @@ func main() {
func ml() nf.HandlerFunc {
return func(c *nf.Ctx) error {
log.Printf("[ML] [%s] - [%s]", c.Method, c.Path())
return c.Next()
index := []byte(`<h1>my not found</h1>`)
c.Set("Content-Type", "text/html")
_, err := c.Write(index)
return err
}
}