From b6e507d5c39fbdd8e0868da8601678531810a8e5 Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Mon, 7 Apr 2014 15:24:27 +0200 Subject: Added support to add API resources with a wrapper handler function. --- core.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core.go b/core.go index 3aa0c7c..1c16cfb 100644 --- a/core.go +++ b/core.go @@ -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 { -- cgit