-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
router.go
150 lines (127 loc) · 3.78 KB
/
router.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package main
import (
"net/http"
beegomux "github.com/beego/mux"
"github.com/bmf-san/goblin"
"github.com/dimfeld/httptreemux/v5"
"github.com/gin-gonic/gin"
"github.com/go-chi/chi/v5"
ozzorouting "github.com/go-ozzo/ozzo-routing/v2"
"github.com/gocraft/web"
gorillamux "github.com/gorilla/mux"
"github.com/julienschmidt/httprouter"
"github.com/labstack/echo"
"github.com/lkeix/techbook13-sample/router"
"github.com/naoina/denco"
"github.com/nissy/bon"
"github.com/uptrace/bunrouter"
"github.com/vardius/gorouter/v4"
)
// route is a struct for route.
type route struct {
path string
reqPath string
}
func loadServeMux(r route) http.Handler {
router := http.NewServeMux()
handler := http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {})
router.HandleFunc(r.path, handler)
return router
}
func loadGoblin(r route) http.Handler {
router := goblin.NewRouter()
handler := http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {})
router.Methods(http.MethodGet).Handler(r.path, handler)
return router
}
func loadHTTPRouter(r route) http.Handler {
router := httprouter.New()
handler := func(_ http.ResponseWriter, _ *http.Request, _ httprouter.Params) {}
router.GET(r.path, handler)
return router
}
func loadChi(r route) http.Handler {
router := chi.NewRouter()
handler := http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {})
router.Get(r.path, handler)
return router
}
func loadGin(r route) http.Handler {
gin.SetMode(gin.ReleaseMode)
router := gin.New()
handler := func(_ *gin.Context) {}
router.GET(r.path, handler)
return router
}
func loadBunRouter(r route) http.Handler {
router := bunrouter.New()
handler := func(_ http.ResponseWriter, _ bunrouter.Request) error { return nil }
router.GET(r.path, handler)
return router
}
func loadHTTPTreeMux(r route) http.Handler {
router := httptreemux.NewContextMux()
handler := http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {})
router.GET(r.path, handler)
return router
}
func loadBeegoMux(r route) http.Handler {
router := beegomux.New()
handler := http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {})
router.Get(r.path, handler)
return router
}
func loadGorillaMux(r route) http.Handler {
router := gorillamux.NewRouter()
handler := http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {})
router.HandleFunc(r.path, handler)
return router
}
func loadBon(r route) http.Handler {
router := bon.NewRouter()
handler := http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {})
router.Get(r.path, handler)
return router
}
func loadDenco(r route) http.Handler {
mux := denco.NewMux()
h := func(w http.ResponseWriter, r *http.Request, _ denco.Params) {}
handler, err := mux.Build([]denco.Handler{
mux.GET(r.path, h),
})
if err != nil {
panic(err)
}
return handler
}
func loadEcho(r route) http.Handler {
e := echo.New()
handler := func(_ echo.Context) error { return nil }
e.GET(r.path, handler)
return e
}
type GocraftWebContext struct{}
func (c *GocraftWebContext) gocraftwebHandler(_ web.ResponseWriter, _ *web.Request) {
}
func loadGocraftWeb(r route) http.Handler {
router := web.New(GocraftWebContext{}).Get(r.path, (*GocraftWebContext).gocraftwebHandler)
return router
}
func loadGorouter(r route) http.Handler {
router := gorouter.New()
handler := http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {})
router.GET(r.path, handler)
return router
}
func loadOzzoRouting(r route) http.Handler {
router := ozzorouting.New()
handler := func(_ *ozzorouting.Context) error { return nil }
router.Get(r.path, handler)
return router
}
func loadN9tE9Routing(r route) http.Handler {
router := router.NewRouter()
handler := http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {})
router.Insert(r.path, handler)
return router
}