aboutsummaryrefslogtreecommitdiff
path: root/core.go
diff options
context:
space:
mode:
authorDoug Black <doug@dougblack.io>2014-03-29 23:13:46 -0700
committerDoug Black <doug@dougblack.io>2014-03-29 23:13:46 -0700
commita59d2f63e6ffceff251e2d14eb313f33f0ea148e (patch)
treef90238cd5c97b5b818ed43b9ceee3f09140de70a /core.go
parentMerge pull request #16 from dmathieu/setup_ci (diff)
parentUpdated type in the README (diff)
downloadsleepy-a59d2f63e6ffceff251e2d14eb313f33f0ea148e.tar.gz
sleepy-a59d2f63e6ffceff251e2d14eb313f33f0ea148e.tar.bz2
sleepy-a59d2f63e6ffceff251e2d14eb313f33f0ea148e.zip
Merge pull request #17 from oleksandr/master
Added access to request headers and ability to specify response headers.
Diffstat (limited to 'core.go')
-rw-r--r--core.go17
1 files changed, 11 insertions, 6 deletions
diff --git a/core.go b/core.go
index b90e2ec..7caaca2 100644
--- a/core.go
+++ b/core.go
@@ -18,25 +18,25 @@ const (
// GetSupported is the interface that provides the Get
// method a resource must support to receive HTTP GETs.
type GetSupported interface {
- Get(url.Values) (int, interface{})
+ Get(url.Values, map[string][]string) (int, interface{}, map[string][]string)
}
// PostSupported is the interface that provides the Post
// method a resource must support to receive HTTP POSTs.
type PostSupported interface {
- Post(url.Values) (int, interface{})
+ Post(url.Values, map[string][]string) (int, interface{}, map[string][]string)
}
// PutSupported is the interface that provides the Put
// method a resource must support to receive HTTP PUTs.
type PutSupported interface {
- Put(url.Values) (int, interface{})
+ Put(url.Values, map[string][]string) (int, interface{}, map[string][]string)
}
// DeleteSupported is the interface that provides the Delete
// method a resource must support to receive HTTP DELETEs.
type DeleteSupported interface {
- Delete(url.Values) (int, interface{})
+ Delete(url.Values, map[string][]string) (int, interface{}, map[string][]string)
}
// An API manages a group of resources by routing requests
@@ -63,7 +63,7 @@ func (api *API) requestHandler(resource interface{}) http.HandlerFunc {
return
}
- var handler func(url.Values) (int, interface{})
+ var handler func(url.Values, map[string][]string) (int, interface{}, map[string][]string)
switch request.Method {
case GET:
@@ -89,13 +89,18 @@ func (api *API) requestHandler(resource interface{}) http.HandlerFunc {
return
}
- code, data := handler(request.Form)
+ code, data, headers := handler(request.Form, request.Header)
content, err := json.Marshal(data)
if err != nil {
rw.WriteHeader(http.StatusInternalServerError)
return
}
+ for name, values := range headers {
+ for _, value := range values {
+ rw.Header().Add(name, value)
+ }
+ }
rw.WriteHeader(code)
rw.Write(content)
}
bgstack15