aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Black <dougblack@gatech.edu>2014-01-24 07:56:47 -0800
committerDoug Black <dougblack@gatech.edu>2014-01-24 07:56:47 -0800
commitb77ada9a5a4ae049f2b5f3eff6ca7a66a154f49d (patch)
tree8ebad8046d0930f4942ddb1a14b1c279b232db90
parentgo fmt (diff)
downloadsleepy-b77ada9a5a4ae049f2b5f3eff6ca7a66a154f49d.tar.gz
sleepy-b77ada9a5a4ae049f2b5f3eff6ca7a66a154f49d.tar.bz2
sleepy-b77ada9a5a4ae049f2b5f3eff6ca7a66a154f49d.zip
reorg
-rw-r--r--core.go26
-rw-r--r--http.go26
-rw-r--r--tests/test.go43
3 files changed, 70 insertions, 25 deletions
diff --git a/core.go b/core.go
index 3ef4029..e0e4a8a 100644
--- a/core.go
+++ b/core.go
@@ -5,36 +5,12 @@ import (
)
type Resource interface {
- Get(p [string][]string) string
+ Get(map[string][]string) string
Post(map[string][]string) string
Put(map[string][]string) string
Delete(map[string][]string) string
}
-type GetNotSupported struct{}
-
-func (GetNotSupported) Get(map[string][]string) string {
- return "Nope."
-}
-
-type PostNotSupported struct{}
-
-func (PostNotSupported) Post(map[string][]string) string {
- return "Nope."
-}
-
-type PutNotSupported struct{}
-
-func (PutNotSupported) Put(map[string][]string) string {
- return "Nope."
-}
-
-type DeleteNotSupported struct{}
-
-func (DeleteNotSupported) Delete(map[string][]string) string {
- return "Nope."
-}
-
type Route struct {
resource Resource
path string
diff --git a/http.go b/http.go
new file mode 100644
index 0000000..712a080
--- /dev/null
+++ b/http.go
@@ -0,0 +1,26 @@
+package sleepy
+
+type GetNotSupported struct{}
+
+func (GetNotSupported) Get(map[string][]string) string {
+ return "Nope."
+}
+
+type PostNotSupported struct{}
+
+func (PostNotSupported) Post(map[string][]string) string {
+ return "Nope."
+}
+
+type PutNotSupported struct{}
+
+func (PutNotSupported) Put(map[string][]string) string {
+ return "Nope."
+}
+
+type DeleteNotSupported struct{}
+
+func (DeleteNotSupported) Delete(map[string][]string) string {
+ return "Nope."
+}
+
diff --git a/tests/test.go b/tests/test.go
new file mode 100644
index 0000000..055067c
--- /dev/null
+++ b/tests/test.go
@@ -0,0 +1,43 @@
+package main
+
+import (
+ "fmt"
+ "sleepy"
+ "net/http"
+)
+
+type Bar struct {
+ sleepy.PostNotSupported
+ sleepy.PutNotSupported
+ sleepy.DeleteNotSupported
+}
+
+func (b Bar) Get(map[string][]string) string {
+ return "Hello"
+}
+
+type Baz struct {
+ sleepy.PostNotSupported
+ sleepy.PutNotSupported
+ sleepy.DeleteNotSupported
+}
+
+func (b Baz) Get(map[string][]string) string {
+ return "Goodbye"
+}
+
+func main() {
+ bar := new(Bar)
+ baz := new(Baz)
+
+ var api = new(sleepy.Api)
+ api.AddResource(bar, "/bar")
+ api.AddResource(baz, "/baz")
+
+ request1, _ := http.NewRequest("GET", "https://dougblack.io/bar", nil)
+ request2, _ := http.NewRequest("GET", "https://dougblack.io/baz", nil)
+ fmt.Println(api.HandleRequest(request1))
+ fmt.Println(api.HandleRequest(request2))
+
+}
+
bgstack15