@@ -2,27 +2,59 @@ 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+ // Middleware is applied to all routes in this group.
10+ Use (m ... Middleware ) Group
11+
12+ // Group creates a new sub-group with the given prefix and optional middleware.
13+ // The sub-group inherits middleware from the parent group.
14+ Group (prefix string , m ... Middleware ) Group
15+
16+ // DELETE registers a new DELETE route with the given path and handler.
17+ DELETE (path string , h HttpHandle ) RouterNode
18+
19+ // GET registers a new GET route with the given path and handler.
20+ GET (path string , h HttpHandle ) RouterNode
21+
22+ // HEAD registers a new HEAD route with the given path and handler.
23+ HEAD (path string , h HttpHandle ) RouterNode
24+
25+ // OPTIONS registers a new OPTIONS route with the given path and handler.
26+ OPTIONS (path string , h HttpHandle ) RouterNode
27+
28+ // PATCH registers a new PATCH route with the given path and handler.
29+ PATCH (path string , h HttpHandle ) RouterNode
30+
31+ // POST registers a new POST route with the given path and handler.
32+ POST (path string , h HttpHandle ) RouterNode
33+
34+ // PUT registers a new PUT route with the given path and handler.
35+ PUT (path string , h HttpHandle ) RouterNode
36+
37+ // ServerFile registers a file server route with the given path and file root.
38+ ServerFile (path string , fileroot string ) RouterNode
39+
40+ // RegisterRoute registers a new route with the given HTTP method, path and handler.
41+ RegisterRoute (method , path string , h HttpHandle ) RouterNode
42+
43+ // SetNotFoundHandle sets a custom 404 handler for this group.
44+ // This handler takes priority over the app-level NotFoundHandler.
45+ // If a request path starts with the group's prefix but no route matches,
46+ // this handler will be called instead of the global NotFoundHandler.
47+ SetNotFoundHandle (handler StandardHandle ) Group
48+ }
49+
50+ // xGroup is the implementation of Group interface.
51+ type xGroup struct {
52+ prefix string
53+ middlewares []Middleware
54+ allRouterExpress map [string ]struct {}
55+ server * HttpServer
56+ notFoundHandler StandardHandle
57+ }
2658
2759func NewGroup (prefix string , server * HttpServer ) Group {
2860 g := & xGroup {prefix : prefix , server : server , allRouterExpress : make (map [string ]struct {})}
@@ -119,3 +151,12 @@ func (g *xGroup) add(method, path string, handler HttpHandle) RouterNode {
119151 node .Node ().groupMiddlewares = g .middlewares
120152 return node
121153}
154+
155+ // SetNotFoundHandle sets a custom 404 handler for this group.
156+ // This handler takes priority over the app-level NotFoundHandler.
157+ // If a request path starts with the group's prefix but no route matches,
158+ // this handler will be called instead of the global NotFoundHandler.
159+ func (g * xGroup ) SetNotFoundHandle (handler StandardHandle ) Group {
160+ g .notFoundHandler = handler
161+ return g
162+ }
0 commit comments