fix: next (not auto run all handlers)

This commit is contained in:
loveuer
2024-02-20 16:04:44 +08:00
parent 039f4cf8c0
commit 7cf7ec32ac
3 changed files with 56 additions and 12 deletions

34
xtest/midd2/main.go Normal file
View File

@ -0,0 +1,34 @@
package main
import (
"errors"
"github.com/loveuer/nf"
"github.com/loveuer/nf/nft/resp"
"log"
)
func main() {
app := nf.New()
api := app.Group("/api")
api.Get("/hello",
auth(),
func(c *nf.Ctx) error {
return resp.Resp403(c, errors.New("in hello"))
},
)
log.Fatal(app.Run(":80"))
}
func auth() nf.HandlerFunc {
return func(c *nf.Ctx) error {
token := c.Query("token")
if token != "zyp" {
return resp.Resp401(c, errors.New("no auth"))
}
return c.Next()
}
}