@@ -203,56 +203,54 @@ func routeHandler(req *Request, conn Conn) {
203
203
}
204
204
match := cr .MatchStrings (requestPath )
205
205
206
- if len (match ) > 0 {
207
- if len (match [0 ]) != len (requestPath ) {
208
- continue
209
- }
206
+ if len (match [0 ]) != len (requestPath ) {
207
+ continue
208
+ }
210
209
211
- var args vector.Vector
210
+ var args vector.Vector
212
211
213
- handlerType := route .handler .Type ().(* reflect.FuncType )
212
+ handlerType := route .handler .Type ().(* reflect.FuncType )
214
213
215
- //check if the first arg in the handler is a context type
216
- if handlerType .NumIn () > 0 {
217
- if a0 , ok := handlerType .In (0 ).(* reflect.PtrType ); ok {
218
- typ := a0 .Elem ()
219
- if typ == contextType {
220
- args .Push (reflect .NewValue (& ctx ))
221
- }
214
+ //check if the first arg in the handler is a context type
215
+ if handlerType .NumIn () > 0 {
216
+ if a0 , ok := handlerType .In (0 ).(* reflect.PtrType ); ok {
217
+ typ := a0 .Elem ()
218
+ if typ == contextType {
219
+ args .Push (reflect .NewValue (& ctx ))
222
220
}
223
221
}
222
+ }
224
223
225
- for _ , arg := range match [1 :] {
226
- args .Push (reflect .NewValue (arg ))
227
- }
228
-
229
- if len (args ) != handlerType .NumIn () {
230
- log .Stderrf ("Incorrect number of arguments for %s\n " , requestPath )
231
- ctx .Abort (500 , "Server Error" )
232
- return
233
- }
224
+ for _ , arg := range match [1 :] {
225
+ args .Push (reflect .NewValue (arg ))
226
+ }
234
227
235
- valArgs := make ([]reflect.Value , len (args ))
236
- for i , j := range (args ) {
237
- valArgs [i ] = j .(reflect.Value )
238
- }
239
- ret := route .handler .Call (valArgs )[0 ].(* reflect.StringValue ).Get ()
240
-
241
- if ! ctx .responseStarted {
242
- //check if session data is stored
243
- if len (s .Data ) > 0 {
244
- s .save ()
245
- //set the session for half an hour
246
- ctx .SetCookie (sessionKey , s .Id , 1800 )
247
- }
228
+ if len (args ) != handlerType .NumIn () {
229
+ log .Stderrf ("Incorrect number of arguments for %s\n " , requestPath )
230
+ ctx .Abort (500 , "Server Error" )
231
+ return
232
+ }
248
233
249
- conn .StartResponse (200 )
250
- ctx .responseStarted = true
251
- conn .WriteString (ret )
234
+ valArgs := make ([]reflect.Value , len (args ))
235
+ for i , j := range (args ) {
236
+ valArgs [i ] = j .(reflect.Value )
237
+ }
238
+ ret := route .handler .Call (valArgs )[0 ].(* reflect.StringValue ).Get ()
239
+
240
+ if ! ctx .responseStarted {
241
+ //check if session data is stored
242
+ if len (s .Data ) > 0 {
243
+ s .save ()
244
+ //set the session for half an hour
245
+ ctx .SetCookie (sessionKey , s .Id , 1800 )
252
246
}
253
247
254
- return
248
+ conn .StartResponse (200 )
249
+ ctx .responseStarted = true
250
+ conn .WriteString (ret )
255
251
}
252
+
253
+ return
256
254
}
257
255
258
256
ctx .Abort (404 , "Page not found" )
0 commit comments