34
34
http.Handler
35
35
// Handle sets the HandleFunc for a given HTTP method and path.
36
36
Handle (method , path string , handle HandleFunc )
37
+ // Lookup returns the HandleFunc associated with the given HTTP method and path.
38
+ Lookup (method , path string ) HandleFunc
37
39
}
38
40
39
41
// HandleFunc provides the implementation for an API endpoint.
@@ -57,15 +59,19 @@ type (
57
59
58
60
// defaultVersionMux is the default goa API version specific mux.
59
61
defaultVersionMux struct {
60
- router * httprouter.Router
62
+ router * httprouter.Router
63
+ handles map [string ]HandleFunc
61
64
}
62
65
)
63
66
64
67
// NewMux creates a top level mux using the default goa mux implementation.
65
68
func NewMux () ServeMux {
66
69
return & DefaultMux {
67
- defaultVersionMux : & defaultVersionMux {router : httprouter .New ()},
68
- selectVersion : PathSelectVersionFunc ("/:version" ),
70
+ defaultVersionMux : & defaultVersionMux {
71
+ router : httprouter .New (),
72
+ handles : make (map [string ]HandleFunc ),
73
+ },
74
+ selectVersion : PathSelectVersionFunc ("/:version" ),
69
75
}
70
76
}
71
77
@@ -173,9 +179,15 @@ func (m *defaultVersionMux) Handle(method, path string, handle HandleFunc) {
173
179
}
174
180
handle (rw , req , params )
175
181
}
182
+ m .handles [method + path ] = handle
176
183
m .router .Handle (method , path , hthandle )
177
184
}
178
185
186
+ // Lookup returns the HandleFunc associated with the given method and path.
187
+ func (m * defaultVersionMux ) Lookup (method , path string ) HandleFunc {
188
+ return m .handles [method + path ]
189
+ }
190
+
179
191
// ServeHTTP is the function called back by the underlying HTTP server to handle incoming requests.
180
192
func (m * defaultVersionMux ) ServeHTTP (rw http.ResponseWriter , req * http.Request ) {
181
193
m .router .ServeHTTP (rw , req )
0 commit comments