diff --git a/nf.go b/nf.go index d8b94f4..9692fc4 100644 --- a/nf.go +++ b/nf.go @@ -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 { diff --git a/router.go b/router.go index d796f8d..b91da52 100644 --- a/router.go +++ b/router.go @@ -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) diff --git a/xtest/midd/main.go b/xtest/midd/main.go new file mode 100644 index 0000000..eebafce --- /dev/null +++ b/xtest/midd/main.go @@ -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() + } +}