aboutsummaryrefslogtreecommitdiff
path: root/core.go
diff options
context:
space:
mode:
authorDoug Black <doug@dougblack.io>2014-04-24 21:12:33 -0700
committerDoug Black <doug@dougblack.io>2014-04-24 21:12:33 -0700
commit86aeaf0b4a3f13c0eef4d9d50ca90a19d9dc8e6e (patch)
treeee487f7a6d3f2b1b4a5c846b0ff3c6c1605a04fc /core.go
parentMerge pull request #23 from strukturag/patch_and_head_support (diff)
parentAdded support to add API resources with a wrapper handler function. (diff)
downloadsleepy-86aeaf0b4a3f13c0eef4d9d50ca90a19d9dc8e6e.tar.gz
sleepy-86aeaf0b4a3f13c0eef4d9d50ca90a19d9dc8e6e.tar.bz2
sleepy-86aeaf0b4a3f13c0eef4d9d50ca90a19d9dc8e6e.zip
Merge pull request #21 from strukturag/wrapper_support
Added support to add API resources with a wrapper handler function.
Diffstat (limited to 'core.go')
-rw-r--r--core.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/core.go b/core.go
index 4d5e6c6..631d76d 100644
--- a/core.go
+++ b/core.go
@@ -149,6 +149,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 {
bgstack15