diff options
author | Simon Eisenmann <simon@struktur.de> | 2014-04-07 15:24:27 +0200 |
---|---|---|
committer | Simon Eisenmann <simon@struktur.de> | 2014-04-07 15:24:27 +0200 |
commit | b6e507d5c39fbdd8e0868da8601678531810a8e5 (patch) | |
tree | 8c31d5c5ed18217d3af17410aa00ade4ae59ca40 /core.go | |
parent | s/muxPointer/mux/ (diff) | |
download | sleepy-b6e507d5c39fbdd8e0868da8601678531810a8e5.tar.gz sleepy-b6e507d5c39fbdd8e0868da8601678531810a8e5.tar.bz2 sleepy-b6e507d5c39fbdd8e0868da8601678531810a8e5.zip |
Added support to add API resources with a wrapper handler function.
Diffstat (limited to 'core.go')
-rw-r--r-- | core.go | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -127,6 +127,15 @@ func (api *API) AddResource(resource interface{}, paths ...string) { } } +// AddResourceWithWrapper behaves exactly like AddResource but wraps +// the generated handler function with a give wrapper function to allow +// to hook in Gzip support and similar. +func (api *API) AddResourceWithWrapper(resource interface{}, wrapper func(handler http.HandlerFunc) http.HandlerFunc, paths ...string) { + for _, path := range paths { + api.Mux().HandleFunc(path, wrapper(api.requestHandler(resource))) + } +} + // Start causes the API to begin serving requests on the given port. func (api *API) Start(port int) error { if !api.muxInitialized { |