diff options
author | Doug Black <dblack@twilio.com> | 2014-01-27 23:33:11 -0500 |
---|---|---|
committer | Doug Black <dblack@twilio.com> | 2014-01-27 23:33:11 -0500 |
commit | 77816cdb2c0ca37b6ce62428f642dac4fd853a39 (patch) | |
tree | 50e29fe7f9e04ad8f061f5a2d129ac1cee2766ef /core.go | |
parent | fixes suggested by @macu (diff) | |
download | sleepy-77816cdb2c0ca37b6ce62428f642dac4fd853a39.tar.gz sleepy-77816cdb2c0ca37b6ce62428f642dac4fd853a39.tar.bz2 sleepy-77816cdb2c0ca37b6ce62428f642dac4fd853a39.zip |
support adding one resource on multiple paths
Diffstat (limited to 'core.go')
-rw-r--r-- | core.go | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -100,12 +100,15 @@ func (api *API) requestHandler(resource interface{}) http.HandlerFunc { } // AddResource adds a new resource to an API. The API will route -// requests to the matching HTTP method on the resource. -func (api *API) AddResource(resource interface{}, path string) { +// requests that match one of the given paths to the matching HTTP +// method on the resource. +func (api *API) AddResource(resource interface{}, paths ...string) { if api.mux == nil { api.mux = http.NewServeMux() } - api.mux.HandleFunc(path, api.requestHandler(resource)) + for _, path := range paths { + api.mux.HandleFunc(path, api.requestHandler(resource)) + } } // Start causes the API to begin serving requests on the given port. |