From 77816cdb2c0ca37b6ce62428f642dac4fd853a39 Mon Sep 17 00:00:00 2001 From: Doug Black Date: Mon, 27 Jan 2014 23:33:11 -0500 Subject: support adding one resource on multiple paths --- core.go | 9 ++++++--- tests/test.go | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core.go b/core.go index 5001261..e5ab4a4 100644 --- a/core.go +++ b/core.go @@ -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. diff --git a/tests/test.go b/tests/test.go index 6e0d936..b316043 100644 --- a/tests/test.go +++ b/tests/test.go @@ -19,7 +19,7 @@ func main() { item := new(Item) var api = sleepy.NewAPI() - api.AddResource(item, "/items") + api.AddResource(item, "/items", "/bar", "/baz") api.Start(3000) } -- cgit