nf/xtest/midd/main.go

29 lines
446 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-20 15:34:00 +08:00
2024-02-19 17:08:13 +08:00
app.Use(ml())
2024-02-19 16:00:56 +08:00
2024-02-20 15:34:00 +08:00
log.Fatal(app.Run(":80"))
2024-02-19 16:00:56 +08:00
}
func ml() nf.HandlerFunc {
return func(c *nf.Ctx) error {
2024-02-19 17:08:13 +08:00
index := []byte(`<h1>my not found</h1>`)
c.Set("Content-Type", "text/html")
2024-02-20 15:34:00 +08:00
c.Status(403)
2024-02-19 17:08:13 +08:00
_, err := c.Write(index)
return err
2024-02-19 16:00:56 +08:00
}
}