aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Black <dougblack@gatech.edu>2014-01-23 23:32:38 -0800
committerDoug Black <dougblack@gatech.edu>2014-01-23 23:32:38 -0800
commit774ef186c9e7ad648d6c74d97d66222414ba7392 (patch)
tree765ab3251a28a987da091f93b60e0704318b53b5
parentadd mechanism for specifying unimplemented methods and dynamic dispatch to a ... (diff)
downloadsleepy-774ef186c9e7ad648d6c74d97d66222414ba7392.tar.gz
sleepy-774ef186c9e7ad648d6c74d97d66222414ba7392.tar.bz2
sleepy-774ef186c9e7ad648d6c74d97d66222414ba7392.zip
go fmt
-rw-r--r--core.go57
1 files changed, 32 insertions, 25 deletions
diff --git a/core.go b/core.go
index c6f56ad..3ef4029 100644
--- a/core.go
+++ b/core.go
@@ -5,27 +5,34 @@ import (
)
type Resource interface {
- Get(map[string][]string) string
- Post(map[string][]string) string
- Put(map[string][]string) string
- Delete(map[string][]string) string
+ Get(p [string][]string) string
+ Post(map[string][]string) string
+ Put(map[string][]string) string
+ Delete(map[string][]string) string
}
-type GetNotSupported struct {}
+type GetNotSupported struct{}
+
func (GetNotSupported) Get(map[string][]string) string {
- return "Nope."
+ return "Nope."
}
-type PostNotSupported struct {}
+
+type PostNotSupported struct{}
+
func (PostNotSupported) Post(map[string][]string) string {
- return "Nope."
+ return "Nope."
}
-type PutNotSupported struct {}
+
+type PutNotSupported struct{}
+
func (PutNotSupported) Put(map[string][]string) string {
- return "Nope."
+ return "Nope."
}
-type DeleteNotSupported struct {}
+
+type DeleteNotSupported struct{}
+
func (DeleteNotSupported) Delete(map[string][]string) string {
- return "Nope."
+ return "Nope."
}
type Route struct {
@@ -51,19 +58,19 @@ func (api *Api) matchResource(path string) Resource {
}
func (api *Api) dispatchRequest(request *http.Request, resource Resource) string {
- method := request.Method
-
- switch method {
- case "GET":
- return resource.Get(nil)
- case "POST":
- return resource.Post(nil)
- case "PUT":
- return resource.Put(nil)
- case "DELETE":
- return resource.Delete(nil)
- }
- return "Not implemented!"
+ method := request.Method
+
+ switch method {
+ case "GET":
+ return resource.Get(nil)
+ case "POST":
+ return resource.Post(nil)
+ case "PUT":
+ return resource.Put(nil)
+ case "DELETE":
+ return resource.Delete(nil)
+ }
+ return "Not implemented!"
}
func (api *Api) HandleRequest(request *http.Request) string {
bgstack15