File tree 2 files changed +17
-5
lines changed
2 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -13,11 +13,10 @@ var defaultRequestContentType string
13
13
14
14
// Request is a wrapper for a http Request that provides convenience methods
15
15
type Request struct {
16
- Request * http.Request
17
- pathParameters map [string ]string
18
- attributes map [string ]interface {} // for storing request-scoped values
19
- selectedRoutePath string // root path + route path that matched the request, e.g. /meetings/{id}/attendees
20
- selectedRoute * Route
16
+ Request * http.Request
17
+ pathParameters map [string ]string
18
+ attributes map [string ]interface {} // for storing request-scoped values
19
+ selectedRoute * Route // is nil when no route was matched
21
20
}
22
21
23
22
func NewRequest (httpRequest * http.Request ) * Request {
@@ -114,11 +113,20 @@ func (r Request) Attribute(name string) interface{} {
114
113
}
115
114
116
115
// SelectedRoutePath root path + route path that matched the request, e.g. /meetings/{id}/attendees
116
+ // If no route was matched then return an empty string.
117
117
func (r Request ) SelectedRoutePath () string {
118
+ if r .selectedRoute == nil {
119
+ return ""
120
+ }
121
+ // skip creating an accessor
118
122
return r .selectedRoute .Path
119
123
}
120
124
121
125
// SelectedRoute returns a reader to access the selected Route by the container
126
+ // Returns nil if no route was matched.
122
127
func (r Request ) SelectedRoute () RouteReader {
128
+ if r .selectedRoute == nil {
129
+ return nil
130
+ }
123
131
return routeAccessor {route : r .selectedRoute }
124
132
}
Original file line number Diff line number Diff line change @@ -383,6 +383,10 @@ func newSelectedRouteTestingService() *WebService {
383
383
}
384
384
385
385
func selectedRouteChecker (req * Request , resp * Response ) {
386
+ if req .SelectedRoute () == nil {
387
+ resp .InternalServerError ()
388
+ return
389
+ }
386
390
if req .SelectedRoutePath () != pathGetFriends {
387
391
resp .InternalServerError ()
388
392
}
You can’t perform that action at this time.
0 commit comments