@@ -2,27 +2,43 @@ package dotweb
22
33import "reflect"
44
5- type (
6- Group interface {
7- Use (m ... Middleware ) Group
8- Group (prefix string , m ... Middleware ) Group
9- DELETE (path string , h HttpHandle ) RouterNode
10- GET (path string , h HttpHandle ) RouterNode
11- HEAD (path string , h HttpHandle ) RouterNode
12- OPTIONS (path string , h HttpHandle ) RouterNode
13- PATCH (path string , h HttpHandle ) RouterNode
14- POST (path string , h HttpHandle ) RouterNode
15- PUT (path string , h HttpHandle ) RouterNode
16- ServerFile (path string , fileroot string ) RouterNode
17- RegisterRoute (method , path string , h HttpHandle ) RouterNode
18- }
19- xGroup struct {
20- prefix string
21- middlewares []Middleware
22- allRouterExpress map [string ]struct {}
23- server * HttpServer
24- }
25- )
5+ // Group is the interface that wraps the group router methods.
6+ // A Group allows you to create routes with a common prefix and middleware chain.
7+ type Group interface {
8+ // Use registers middleware(s) to the group.
9+ Use (m ... Middleware ) Group
10+ // Group creates a new sub-group with prefix and optional sub-group-level middleware.
11+ Group (prefix string , m ... Middleware ) Group
12+ // DELETE registers a new DELETE route with the given path and handler.
13+ DELETE (path string , h HttpHandle ) RouterNode
14+ // GET registers a new GET route with the given path and handler.
15+ GET (path string , h HttpHandle ) RouterNode
16+ // HEAD registers a new HEAD route with the given path and handler.
17+ HEAD (path string , h HttpHandle ) RouterNode
18+ // OPTIONS registers a new OPTIONS route with the given path and handler.
19+ OPTIONS (path string , h HttpHandle ) RouterNode
20+ // PATCH registers a new PATCH route with the given path and handler.
21+ PATCH (path string , h HttpHandle ) RouterNode
22+ // POST registers a new POST route with the given path and handler.
23+ POST (path string , h HttpHandle ) RouterNode
24+ // PUT registers a new PUT route with the given path and handler.
25+ PUT (path string , h HttpHandle ) RouterNode
26+ // ServerFile registers a file server route with the given path and file root.
27+ ServerFile (path string , fileroot string ) RouterNode
28+ // RegisterRoute registers a new route with the given HTTP method, path and handler.
29+ RegisterRoute (method , path string , h HttpHandle ) RouterNode
30+ // SetNotFoundHandle sets a custom 404 handler for this group.
31+ SetNotFoundHandle (handler StandardHandle ) Group
32+ }
33+
34+ // xGroup is the implementation of Group interface.
35+ type xGroup struct {
36+ prefix string
37+ middlewares []Middleware
38+ allRouterExpress map [string ]struct {}
39+ server * HttpServer
40+ notFoundHandler StandardHandle
41+ }
2642
2743func NewGroup (prefix string , server * HttpServer ) Group {
2844 g := & xGroup {prefix : prefix , server : server , allRouterExpress : make (map [string ]struct {})}
@@ -119,3 +135,14 @@ func (g *xGroup) add(method, path string, handler HttpHandle) RouterNode {
119135 node .Node ().groupMiddlewares = g .middlewares
120136 return node
121137}
138+
139+ // SetNotFoundHandle sets a custom 404 handler for this group.
140+ // This handler takes priority over the app-level NotFoundHandler.
141+ // If a request path starts with the group's prefix but no route matches,
142+ // this handler will be called instead of the global NotFoundHandler.
143+ // SetNotFoundHandle sets custom 404 handler for this group.
144+ // This handler takes priority over the app-level NotFoundHandler.
145+ func (g * xGroup ) SetNotFoundHandle (handler StandardHandle ) Group {
146+ g .notFoundHandler = handler
147+ return g
148+ }
0 commit comments