-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample_group_test.go
More file actions
44 lines (35 loc) · 1.1 KB
/
Copy pathexample_group_test.go
File metadata and controls
44 lines (35 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package gohttputil_test
import gohttputil "github.com/asif-mahmud/go-httputil"
// Example_group shows grouping multiple routes
func Example_group() {
// create mux instance
m := gohttputil.New()
// define a group of routes
m.Group("/api/v1").
// group level middlewares. these middlewares
// will be applied to all routes defined in this group
Use(groupMiddleware1).
Use(groupMiddleware2).
// define handlers for a route
Route("/orders", func(rh gohttputil.RouteHandler) {
rh.
// no route level middleware will be applied to GET handler
Get(handler1).
// middleware1 will be applied to POST handler
Use(middleware1).
Post(handler1).
// no middleware applied to PUT method handler
Put(handler1)
}).
// define handlers for another route under same group
Route("/users", func(rh gohttputil.RouteHandler) {
rh.
// no route level middleware will be applied to GET handler
Get(handler1).
// middleware1 will be applied to POST handler
Use(middleware1).
Post(handler1).
// no middleware applied to PUT method handler
Put(handler1)
})
}