diff options
author | Doug Black <dougblack@gatech.edu> | 2014-01-23 21:01:57 -0800 |
---|---|---|
committer | Doug Black <dougblack@gatech.edu> | 2014-01-23 21:01:57 -0800 |
commit | e8e9d2e14287a7e111c2e9f0a5a11237d14a7ce4 (patch) | |
tree | 6b292ce9b6337aefb0c98e32b5c910ee1326e26f | |
download | sleepy-e8e9d2e14287a7e111c2e9f0a5a11237d14a7ce4.tar.gz sleepy-e8e9d2e14287a7e111c2e9f0a5a11237d14a7ce4.tar.bz2 sleepy-e8e9d2e14287a7e111c2e9f0a5a11237d14a7ce4.zip |
initial commit
-rw-r--r-- | core.go | 40 |
1 files changed, 40 insertions, 0 deletions
@@ -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}) +} |