nf/xtest/midd/main.go

31 lines
548 B
Go
Raw Normal View History

2024-02-19 16:00:56 +08:00
package main
import (
"github.com/loveuer/nf"
"log"
)
func main() {
2024-02-19 17:08:13 +08:00
app := nf.New(nf.Config{DisableLogger: false})
2024-02-19 16:00:56 +08:00
app.Get("/hello", func(c *nf.Ctx) error {
return c.SendString("world")
})
2024-02-19 17:08:13 +08:00
app.Get("/panic", func(c *nf.Ctx) error {
panic("panic")
})
app.Use(ml())
2024-02-19 16:00:56 +08:00
log.Fatal(app.Run(":7777"))
}
func ml() nf.HandlerFunc {
return func(c *nf.Ctx) error {
log.Printf("[ML] [%s] - [%s]", c.Method, c.Path())
2024-02-19 17:08:13 +08:00
index := []byte(`<h1>my not found</h1>`)
c.Set("Content-Type", "text/html")
_, err := c.Write(index)
return err
2024-02-19 16:00:56 +08:00
}
}