@@ -18,11 +18,14 @@ import (
1818 "github.com/stretchr/testify/assert"
1919 "github.com/stretchr/testify/require"
2020 "github.com/urfave/negroni"
21+ "goji.io"
22+ "goji.io/pat"
2123
2224 metricsprometheus "github.com/slok/go-http-metrics/metrics/prometheus"
2325 "github.com/slok/go-http-metrics/middleware"
2426 echomiddleware "github.com/slok/go-http-metrics/middleware/echo"
2527 ginmiddleware "github.com/slok/go-http-metrics/middleware/gin"
28+ gojimiddleware "github.com/slok/go-http-metrics/middleware/goji"
2629 gorestfulmiddleware "github.com/slok/go-http-metrics/middleware/gorestful"
2730 httproutermiddleware "github.com/slok/go-http-metrics/middleware/httprouter"
2831 negronimiddleware "github.com/slok/go-http-metrics/middleware/negroni"
@@ -50,6 +53,7 @@ func TestMiddlewarePrometheus(t *testing.T) {
5053 "Gorestful" : {handler : prepareHandlerGorestful },
5154 "Gin" : {handler : prepareHandlerGin },
5255 "Echo" : {handler : prepareHandlerEcho },
56+ "Goji" : {handler : prepareHandlerGoji },
5357 }
5458
5559 for name , test := range tests {
@@ -139,8 +143,7 @@ func prepareHandlerSTD(m middleware.Middleware, hc []handlerConfig) http.Handler
139143
140144 time .Sleep (h .SleepDuration )
141145 w .WriteHeader (h .Code )
142- // nolint: errcheck
143- w .Write ([]byte (h .ReturnData ))
146+ w .Write ([]byte (h .ReturnData )) // nolint: errcheck
144147 }))
145148 }
146149
@@ -163,8 +166,7 @@ func prepareHandlerNegroni(m middleware.Middleware, hc []handlerConfig) http.Han
163166
164167 time .Sleep (h .SleepDuration )
165168 w .WriteHeader (h .Code )
166- // nolint: errcheck
167- w .Write ([]byte (h .ReturnData ))
169+ w .Write ([]byte (h .ReturnData )) // nolint: errcheck
168170 }))
169171 }
170172
@@ -185,8 +187,7 @@ func prepareHandlerHTTPRouter(m middleware.Middleware, hc []handlerConfig) http.
185187 hr := func (w http.ResponseWriter , _ * http.Request , _ httprouter.Params ) {
186188 time .Sleep (h .SleepDuration )
187189 w .WriteHeader (h .Code )
188- // nolint: errcheck
189- w .Write ([]byte (h .ReturnData ))
190+ w .Write ([]byte (h .ReturnData )) // nolint: errcheck
190191 }
191192
192193 // Setup middleware on each of the routes.
@@ -208,8 +209,7 @@ func prepareHandlerGorestful(m middleware.Middleware, hc []handlerConfig) http.H
208209 ws .Route (ws .Method (h .Method ).Path (h .Path ).To (func (_ * gorestful.Request , resp * gorestful.Response ) {
209210 time .Sleep (h .SleepDuration )
210211 resp .WriteHeader (h .Code )
211- // nolint: errcheck
212- resp .Write ([]byte (h .ReturnData ))
212+ resp .Write ([]byte (h .ReturnData )) // nolint: errcheck
213213 }))
214214 }
215215 c .Add (ws )
@@ -250,3 +250,21 @@ func prepareHandlerEcho(m middleware.Middleware, hc []handlerConfig) http.Handle
250250
251251 return e
252252}
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