fix: root middleware not work
This commit is contained in:
parent
1c9c21e294
commit
de3ce47671
2
nf.go
2
nf.go
@ -53,7 +53,7 @@ func New(config ...Config) *App {
|
|||||||
app.config = defaultConfig
|
app.config = defaultConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
app.RouterGroup = &RouterGroup{app: app}
|
app.RouterGroup = &RouterGroup{app: app, prefix: "/"}
|
||||||
app.groups = []*RouterGroup{app.RouterGroup}
|
app.groups = []*RouterGroup{app.RouterGroup}
|
||||||
|
|
||||||
if !app.config.DisableLogger {
|
if !app.config.DisableLogger {
|
||||||
|
@ -48,7 +48,7 @@ func (r *router) getRoute(method string, path string) (*_node, map[string]string
|
|||||||
root, ok := r.roots[method]
|
root, ok := r.roots[method]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, nil
|
return &_node{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
n := root.search(searchParts, 0)
|
n := root.search(searchParts, 0)
|
||||||
|
24
xtest/midd/main.go
Normal file
24
xtest/midd/main.go
Normal 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()
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user