@@ -18,11 +18,14 @@ import (
18
18
"github.com/stretchr/testify/assert"
19
19
"github.com/stretchr/testify/require"
20
20
"github.com/urfave/negroni"
21
+ "goji.io"
22
+ "goji.io/pat"
21
23
22
24
metricsprometheus "github.com/slok/go-http-metrics/metrics/prometheus"
23
25
"github.com/slok/go-http-metrics/middleware"
24
26
echomiddleware "github.com/slok/go-http-metrics/middleware/echo"
25
27
ginmiddleware "github.com/slok/go-http-metrics/middleware/gin"
28
+ gojimiddleware "github.com/slok/go-http-metrics/middleware/goji"
26
29
gorestfulmiddleware "github.com/slok/go-http-metrics/middleware/gorestful"
27
30
httproutermiddleware "github.com/slok/go-http-metrics/middleware/httprouter"
28
31
negronimiddleware "github.com/slok/go-http-metrics/middleware/negroni"
@@ -50,6 +53,7 @@ func TestMiddlewarePrometheus(t *testing.T) {
50
53
"Gorestful" : {handler : prepareHandlerGorestful },
51
54
"Gin" : {handler : prepareHandlerGin },
52
55
"Echo" : {handler : prepareHandlerEcho },
56
+ "Goji" : {handler : prepareHandlerGoji },
53
57
}
54
58
55
59
for name , test := range tests {
@@ -139,8 +143,7 @@ func prepareHandlerSTD(m middleware.Middleware, hc []handlerConfig) http.Handler
139
143
140
144
time .Sleep (h .SleepDuration )
141
145
w .WriteHeader (h .Code )
142
- // nolint: errcheck
143
- w .Write ([]byte (h .ReturnData ))
146
+ w .Write ([]byte (h .ReturnData )) // nolint: errcheck
144
147
}))
145
148
}
146
149
@@ -163,8 +166,7 @@ func prepareHandlerNegroni(m middleware.Middleware, hc []handlerConfig) http.Han
163
166
164
167
time .Sleep (h .SleepDuration )
165
168
w .WriteHeader (h .Code )
166
- // nolint: errcheck
167
- w .Write ([]byte (h .ReturnData ))
169
+ w .Write ([]byte (h .ReturnData )) // nolint: errcheck
168
170
}))
169
171
}
170
172
@@ -185,8 +187,7 @@ func prepareHandlerHTTPRouter(m middleware.Middleware, hc []handlerConfig) http.
185
187
hr := func (w http.ResponseWriter , _ * http.Request , _ httprouter.Params ) {
186
188
time .Sleep (h .SleepDuration )
187
189
w .WriteHeader (h .Code )
188
- // nolint: errcheck
189
- w .Write ([]byte (h .ReturnData ))
190
+ w .Write ([]byte (h .ReturnData )) // nolint: errcheck
190
191
}
191
192
192
193
// Setup middleware on each of the routes.
@@ -208,8 +209,7 @@ func prepareHandlerGorestful(m middleware.Middleware, hc []handlerConfig) http.H
208
209
ws .Route (ws .Method (h .Method ).Path (h .Path ).To (func (_ * gorestful.Request , resp * gorestful.Response ) {
209
210
time .Sleep (h .SleepDuration )
210
211
resp .WriteHeader (h .Code )
211
- // nolint: errcheck
212
- resp .Write ([]byte (h .ReturnData ))
212
+ resp .Write ([]byte (h .ReturnData )) // nolint: errcheck
213
213
}))
214
214
}
215
215
c .Add (ws )
@@ -250,3 +250,21 @@ func prepareHandlerEcho(m middleware.Middleware, hc []handlerConfig) http.Handle
250
250
251
251
return e
252
252
}
253
+
254
+ func prepareHandlerGoji (m middleware.Middleware , hc []handlerConfig ) http.Handler {
255
+ // Setup server and middleware.
256
+ mux := goji .NewMux ()
257
+ mux .Use (gojimiddleware .Handler ("" , m ))
258
+
259
+ // Setup handlers.
260
+ for _ , h := range hc {
261
+ h := h
262
+ mux .HandleFunc (pat .NewWithMethods (h .Path , h .Method ), http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
263
+ time .Sleep (h .SleepDuration )
264
+ w .WriteHeader (h .Code )
265
+ w .Write ([]byte (h .ReturnData )) // nolint: errcheck
266
+ }))
267
+ }
268
+
269
+ return mux
270
+ }
0 commit comments