aboutsummaryrefslogtreecommitdiff
path: root/core.go
diff options
context:
space:
mode:
Diffstat (limited to 'core.go')
-rw-r--r--core.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/core.go b/core.go
new file mode 100644
index 0000000..29dcfcb
--- /dev/null
+++ b/core.go
@@ -0,0 +1,40 @@
+package sleepy
+
+type Resource interface {
+ Get() string
+ // Post
+ // Put
+ // Delete
+}
+
+type Route struct {
+ resource Resource
+ path string
+}
+
+func (route *Route) pathMatch(path string) bool {
+ return route.path == path
+}
+
+type Api struct {
+ routes []Route
+}
+
+func (api *Api) matchResource(path string) Resource {
+ for _, route := range api.routes {
+ if route.pathMatch(path) {
+ return route.resource
+ }
+ }
+ return nil
+}
+
+func (api *Api) HandleRequest(path string) string {
+ resource := api.matchResource(path)
+ return resource.Get()
+}
+
+
+func (api *Api) AddResource(resource Resource, path string) {
+ api.routes = append(api.routes, Route{resource, path})
+}
bgstack15