-
Notifications
You must be signed in to change notification settings - Fork 0
/
route_test.go
53 lines (47 loc) · 1.2 KB
/
route_test.go
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
45
46
47
48
49
50
51
52
53
package route
import (
"github.com/gin-gonic/gin"
)
func ExampleRouteGroup_Handle() {
photos := NewGroup("photos")
photos.Handle("GET", "", queryPhotos)
photos.Handle("GET", "/:id", getPhoto)
photos.printAll()
// Output: GET /photos 1
// GET /photos/:id 1
}
func ExampleRouteGroup_Use() {
photos := NewGroup("photos")
photos.Use(logMiddleware())
photos.Handle("GET", "", queryPhotos)
photos.Handle("GET", "/:id", getPhoto)
photos.printAll()
// Output: GET /photos 2
// GET /photos/:id 2
}
func ExampleRouteGroup_Mount() {
v1 := NewGroup("v1")
photos := NewGroup("photos")
photos.Handle("GET", "", queryPhotos)
photos.Handle("GET", "/:id", getPhoto)
v1.Mount("", photos)
v1.printAll()
// Output: GET /v1/photos 1
// GET /v1/photos/:id 1
}
func ExampleRouteGroup_WithScope() {
v1 := NewGroup("/v1")
v1.WithScope("photos", func(photos *RouteGroup) {
photos.Use(logMiddleware())
photos.Handle("GET", "", logMiddleware(), queryPhotos)
photos.Handle("GET", "/:id", getPhoto)
})
v1.printAll()
// Output: GET /v1/photos 3
// GET /v1/photos/:id 2
}
func logMiddleware() gin.HandlerFunc {
return func(ctx *gin.Context) {}
}
func queryPhotos(ctx *gin.Context) {}
func getPhoto(ctx *gin.Context) {}