fix: root middleware not work

This commit is contained in:
loveuer 2024-02-19 16:00:56 +08:00
parent 1c9c21e294
commit de3ce47671
3 changed files with 26 additions and 2 deletions

2
nf.go
View File

@ -53,7 +53,7 @@ func New(config ...Config) *App {
app.config = defaultConfig
}
app.RouterGroup = &RouterGroup{app: app}
app.RouterGroup = &RouterGroup{app: app, prefix: "/"}
app.groups = []*RouterGroup{app.RouterGroup}
if !app.config.DisableLogger {

View File

@ -48,7 +48,7 @@ func (r *router) getRoute(method string, path string) (*_node, map[string]string
root, ok := r.roots[method]
if !ok {
return nil, nil
return &_node{}, nil
}
n := root.search(searchParts, 0)

24
xtest/midd/main.go Normal file
View File

@ -0,0 +1,24 @@
package main
import (
"github.com/loveuer/nf"
"log"
)
func main() {
app := nf.New()
app.Use(ml())
app.Get("/hello", func(c *nf.Ctx) error {
return c.SendString("world")
})
log.Fatal(app.Run(":7777"))
}
func ml() nf.HandlerFunc {
return func(c *nf.Ctx) error {
log.Printf("[ML] [%s] - [%s]", c.Method, c.Path())
return c.Next()
}
}