-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
44 lines (37 loc) · 851 Bytes
/
main.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
package main
import (
"fmt"
"net/http"
"github.com/tonny-zhang/cotton"
)
func main() {
r := cotton.NewRouter()
{
g1 := r.Group("/v1")
// custom group notfound
g1.NotFound(func(ctx *cotton.Context) {
ctx.String(http.StatusNotFound, "group v1 page not found")
})
// custom group middleware
g1.Use(func(ctx *cotton.Context) {
fmt.Println("g1 middleware")
ctx.Response.Header().Add("group", "v1")
})
g1.Get("/one", func(ctx *cotton.Context) {
ctx.String(http.StatusOK, "/v1/one")
})
}
{
g1 := r.Group("/v2")
g1.NotFound(func(ctx *cotton.Context) {
ctx.String(http.StatusNotFound, "group v2 page not found")
})
g1.Use(func(ctx *cotton.Context) {
ctx.Response.Header().Add("group", "v2")
})
g1.Get("/one", func(ctx *cotton.Context) {
ctx.String(http.StatusOK, "/v2/one")
})
}
r.Run("")
}