aboutsummaryrefslogtreecommitdiff
path: root/core.go
diff options
context:
space:
mode:
authorDoug Black <doug@dougblack.io>2014-04-24 21:12:08 -0700
committerDoug Black <doug@dougblack.io>2014-04-24 21:12:08 -0700
commitf522c3a1b2569edcde055a329751c95e9be6ccd6 (patch)
tree4049e8e1c3519ad19b013914cb6a93b4dc24af94 /core.go
parentMerge pull request #20 from strukturag/pretty_print (diff)
parentAdded support for HEAD and PATCH requests. (diff)
downloadsleepy-f522c3a1b2569edcde055a329751c95e9be6ccd6.tar.gz
sleepy-f522c3a1b2569edcde055a329751c95e9be6ccd6.tar.bz2
sleepy-f522c3a1b2569edcde055a329751c95e9be6ccd6.zip
Merge pull request #23 from strukturag/patch_and_head_support
Added support for HEAD and PATCH requests.
Diffstat (limited to 'core.go')
-rw-r--r--core.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/core.go b/core.go
index b15ca8b..4d5e6c6 100644
--- a/core.go
+++ b/core.go
@@ -13,6 +13,8 @@ const (
POST = "POST"
PUT = "PUT"
DELETE = "DELETE"
+ HEAD = "HEAD"
+ PATCH = "PATCH"
)
// GetSupported is the interface that provides the Get
@@ -39,6 +41,18 @@ type DeleteSupported interface {
Delete(url.Values, http.Header) (int, interface{}, http.Header)
}
+// HeadSupported is the interface that provides the Head
+// method a resource must support to receive HTTP HEADs.
+type HeadSupported interface {
+ Head(url.Values, http.Header) (int, interface{}, http.Header)
+}
+
+// PatchSupported is the interface that provides the Patch
+// method a resource must support to receive HTTP PATCHs.
+type PatchSupported interface {
+ Patch(url.Values, http.Header) (int, interface{}, http.Header)
+}
+
// An API manages a group of resources by routing requests
// to the correct method on a matching resource and marshalling
// the returned data to JSON for the HTTP response.
@@ -82,6 +96,14 @@ func (api *API) requestHandler(resource interface{}) http.HandlerFunc {
if resource, ok := resource.(DeleteSupported); ok {
handler = resource.Delete
}
+ case HEAD:
+ if resource, ok := resource.(HeadSupported); ok {
+ handler = resource.Head
+ }
+ case PATCH:
+ if resource, ok := resource.(PatchSupported); ok {
+ handler = resource.Patch
+ }
}
if handler == nil {
bgstack15