@@ -4,13 +4,14 @@ import (
4
4
"context"
5
5
"expvar"
6
6
"fmt"
7
- "github.com/ixtendio/gow/auth"
8
- "github.com/ixtendio/gow/auth/oauth"
9
- "github.com/ixtendio/gow/errors"
10
- "github.com/ixtendio/gow/middleware"
11
- "github.com/ixtendio/gow/request"
12
- "github.com/ixtendio/gow/response"
13
- "github.com/ixtendio/gow/router"
7
+ "github.com/ixtendio/gofre/auth"
8
+ "github.com/ixtendio/gofre/auth/oauth"
9
+ "github.com/ixtendio/gofre/errors"
10
+ "github.com/ixtendio/gofre/handler"
11
+ "github.com/ixtendio/gofre/middleware"
12
+ "github.com/ixtendio/gofre/request"
13
+ "github.com/ixtendio/gofre/response"
14
+ "github.com/ixtendio/gofre/router"
14
15
"html/template"
15
16
"log"
16
17
"math/rand"
@@ -97,7 +98,7 @@ func NewMuxHandler(config *Config) (*MuxHandler, error) {
97
98
}
98
99
assetsPath := config .ResourcesConfig .AssetsPath
99
100
assetsDirPath := config .ResourcesConfig .AssetsDirPath
100
- r .Handle (http .MethodGet , fmt .Sprintf ("%s/%s/*" , contextPath , assetsPath ), router .Handler2Handler (http .StripPrefix (fmt .Sprintf ("%s/%s/" , contextPath , assetsPath ), http .FileServer (http .Dir (assetsDirPath )))))
101
+ r .Handle (http .MethodGet , fmt .Sprintf ("%s/%s/*" , contextPath , assetsPath ), handler .Handler2Handler (http .StripPrefix (fmt .Sprintf ("%s/%s/" , contextPath , assetsPath ), http .FileServer (http .Dir (assetsDirPath )))))
101
102
}
102
103
return & MuxHandler {
103
104
router : r ,
@@ -121,12 +122,12 @@ func (m *MuxHandler) RegisterCommonMiddlewares(middlewares ...middleware.Middlew
121
122
// If the OAUTH2 flow successfully completes, then the oauth.AccessToken will be passed to context.Context
122
123
// to extract it, you have to use the method oauth.GetAccessTokenFromContext(context.Context)
123
124
124
- func (m * MuxHandler ) HandleOAUTH2 (oauthConfig oauth.Config , handler router .Handler , middlewares ... middleware.Middleware ) {
125
+ func (m * MuxHandler ) HandleOAUTH2 (oauthConfig oauth.Config , handler handler .Handler , middlewares ... middleware.Middleware ) {
125
126
m .HandleOAUTH2WithCustomPaths ("/oauth/initiate" , "/oauth/authorize" , oauthConfig , handler , middlewares ... )
126
127
}
127
128
128
129
// HandleOAUTH2WithCustomPaths registers the necessary handlers to initiate and complete the OAUTH2 flow using custom paths
129
- func (m * MuxHandler ) HandleOAUTH2WithCustomPaths (initiatePath string , authorizeBasePath string , oauthConfig oauth.Config , handler router .Handler , middlewares ... middleware.Middleware ) {
130
+ func (m * MuxHandler ) HandleOAUTH2WithCustomPaths (initiatePath string , authorizeBasePath string , oauthConfig oauth.Config , handler handler .Handler , middlewares ... middleware.Middleware ) {
130
131
cache := oauthConfig .CacheConfig .Cache
131
132
// initiate OAUTH flow handler
132
133
authorizationFlowBasePath := authorizeBasePath
@@ -195,73 +196,73 @@ func (m *MuxHandler) HandleOAUTH2WithCustomPaths(initiatePath string, authorizeB
195
196
196
197
// HandleGet registers a handler with middlewares for GET requests
197
198
// The middlewares will be applied only for this handler
198
- func (m * MuxHandler ) HandleGet (path string , handler router .Handler , middlewares ... middleware.Middleware ) {
199
+ func (m * MuxHandler ) HandleGet (path string , handler handler .Handler , middlewares ... middleware.Middleware ) {
199
200
m .HandleRequest (http .MethodGet , path , handler , middlewares ... )
200
201
}
201
202
202
203
// HandlePost registers a handler with middlewares for POST requests
203
204
// The middlewares will be applied only for this handler
204
- func (m * MuxHandler ) HandlePost (path string , handler router .Handler , middlewares ... middleware.Middleware ) {
205
+ func (m * MuxHandler ) HandlePost (path string , handler handler .Handler , middlewares ... middleware.Middleware ) {
205
206
m .HandleRequest (http .MethodPost , path , handler , middlewares ... )
206
207
}
207
208
208
209
// HandlePut registers a handler with middlewares for PUT requests
209
210
// The middlewares will be applied only for this handler
210
- func (m * MuxHandler ) HandlePut (path string , handler router .Handler , middlewares ... middleware.Middleware ) {
211
+ func (m * MuxHandler ) HandlePut (path string , handler handler .Handler , middlewares ... middleware.Middleware ) {
211
212
m .HandleRequest (http .MethodPut , path , handler , middlewares ... )
212
213
}
213
214
214
215
// HandlePath registers a handler with middlewares for PATCH requests
215
216
// The middlewares will be applied only for this handler
216
- func (m * MuxHandler ) HandlePath (path string , handler router .Handler , middlewares ... middleware.Middleware ) {
217
+ func (m * MuxHandler ) HandlePath (path string , handler handler .Handler , middlewares ... middleware.Middleware ) {
217
218
m .HandleRequest (http .MethodPatch , path , handler , middlewares ... )
218
219
}
219
220
220
221
// HandleDelete registers a handler with middlewares for DELETE requests
221
222
// The middlewares will be applied only for this handler
222
- func (m * MuxHandler ) HandleDelete (path string , handler router .Handler , middlewares ... middleware.Middleware ) {
223
+ func (m * MuxHandler ) HandleDelete (path string , handler handler .Handler , middlewares ... middleware.Middleware ) {
223
224
m .HandleRequest (http .MethodDelete , path , handler , middlewares ... )
224
225
}
225
226
226
227
// HandleRequest registers a handler with middlewares for the specified HTTP method
227
228
// The middlewares will be applied only for this handler
228
- func (m * MuxHandler ) HandleRequest (httpMethod string , path string , handler router .Handler , middlewares ... middleware.Middleware ) {
229
- handler = wrapMiddleware (wrapMiddleware (handler , middlewares ... ), m .commonMiddlewares ... )
229
+ func (m * MuxHandler ) HandleRequest (httpMethod string , path string , h handler .Handler , middlewares ... middleware.Middleware ) {
230
+ h = wrapMiddleware (wrapMiddleware (h , middlewares ... ), m .commonMiddlewares ... )
230
231
var tmpl * template.Template
231
232
if m .webConfig .ResourcesConfig != nil {
232
233
tmpl = m .webConfig .ResourcesConfig .Template
233
234
}
234
235
//expose contextPath and template on request context
235
- handler = wrapMiddleware (handler , func (handler router .Handler ) router .Handler {
236
+ h = wrapMiddleware (h , func (h handler .Handler ) handler .Handler {
236
237
return func (ctx context.Context , r * request.HttpRequest ) (response.HttpResponse , error ) {
237
238
ctx = context .WithValue (ctx , KeyValues , & CtxValues {
238
239
ContextPath : m .webConfig .ContextPath ,
239
240
Template : tmpl ,
240
241
})
241
- return handler (ctx , r )
242
+ return h (ctx , r )
242
243
}
243
244
})
244
- m .router .Handle (httpMethod , path , handler )
245
+ m .router .Handle (httpMethod , path , h )
245
246
}
246
247
247
248
// EnableDebugEndpoints enable debug endpoints
248
249
func (m MuxHandler ) EnableDebugEndpoints () {
249
250
// Register all the standard library debug endpoints.
250
- m .router .Handle (http .MethodGet , "/debug/pprof/" , router .HandlerFunc2Handler (pprof .Index ))
251
- m .router .Handle (http .MethodGet , "/debug/pprof/allocs" , router .HandlerFunc2Handler (pprof .Index ))
252
- m .router .Handle (http .MethodGet , "/debug/pprof/block" , router .HandlerFunc2Handler (pprof .Index ))
253
- m .router .Handle (http .MethodGet , "/debug/pprof/goroutine" , router .HandlerFunc2Handler (pprof .Index ))
254
- m .router .Handle (http .MethodGet , "/debug/pprof/heap" , router .HandlerFunc2Handler (pprof .Index ))
255
- m .router .Handle (http .MethodGet , "/debug/pprof/mutex" , router .HandlerFunc2Handler (pprof .Index ))
256
- m .router .Handle (http .MethodGet , "/debug/pprof/threadcreate" , router .HandlerFunc2Handler (pprof .Index ))
257
- m .router .Handle (http .MethodGet , "/debug/pprof/cmdline" , router .HandlerFunc2Handler (pprof .Cmdline ))
258
- m .router .Handle (http .MethodGet , "/debug/pprof/profile" , router .HandlerFunc2Handler (pprof .Profile ))
259
- m .router .Handle (http .MethodGet , "/debug/pprof/symbol" , router .HandlerFunc2Handler (pprof .Symbol ))
260
- m .router .Handle (http .MethodGet , "/debug/pprof/trace" , router .HandlerFunc2Handler (pprof .Trace ))
261
- m .router .Handle (http .MethodGet , "/debug/vars" , router .Handler2Handler (expvar .Handler ()))
251
+ m .router .Handle (http .MethodGet , "/debug/pprof/" , handler .HandlerFunc2Handler (pprof .Index ))
252
+ m .router .Handle (http .MethodGet , "/debug/pprof/allocs" , handler .HandlerFunc2Handler (pprof .Index ))
253
+ m .router .Handle (http .MethodGet , "/debug/pprof/block" , handler .HandlerFunc2Handler (pprof .Index ))
254
+ m .router .Handle (http .MethodGet , "/debug/pprof/goroutine" , handler .HandlerFunc2Handler (pprof .Index ))
255
+ m .router .Handle (http .MethodGet , "/debug/pprof/heap" , handler .HandlerFunc2Handler (pprof .Index ))
256
+ m .router .Handle (http .MethodGet , "/debug/pprof/mutex" , handler .HandlerFunc2Handler (pprof .Index ))
257
+ m .router .Handle (http .MethodGet , "/debug/pprof/threadcreate" , handler .HandlerFunc2Handler (pprof .Index ))
258
+ m .router .Handle (http .MethodGet , "/debug/pprof/cmdline" , handler .HandlerFunc2Handler (pprof .Cmdline ))
259
+ m .router .Handle (http .MethodGet , "/debug/pprof/profile" , handler .HandlerFunc2Handler (pprof .Profile ))
260
+ m .router .Handle (http .MethodGet , "/debug/pprof/symbol" , handler .HandlerFunc2Handler (pprof .Symbol ))
261
+ m .router .Handle (http .MethodGet , "/debug/pprof/trace" , handler .HandlerFunc2Handler (pprof .Trace ))
262
+ m .router .Handle (http .MethodGet , "/debug/vars" , handler .Handler2Handler (expvar .Handler ()))
262
263
}
263
264
264
- func wrapMiddleware (handler router .Handler , middlewares ... middleware.Middleware ) router .Handler {
265
+ func wrapMiddleware (handler handler .Handler , middlewares ... middleware.Middleware ) handler .Handler {
265
266
wrappedHandlers := handler
266
267
for i := len (middlewares ) - 1 ; i >= 0 ; i -- {
267
268
mid := middlewares [i ]
0 commit comments