diff options
author | Doug Black <dougblack@gatech.edu> | 2014-01-23 21:46:54 -0800 |
---|---|---|
committer | Doug Black <dougblack@gatech.edu> | 2014-01-23 21:46:54 -0800 |
commit | b53ed06f8bf5213b5b652ba0ac0761b1e3d8d587 (patch) | |
tree | 82fed9129f3e7c49976b79f24f74a783502f474b /core.go | |
parent | initial commit (diff) | |
download | sleepy-b53ed06f8bf5213b5b652ba0ac0761b1e3d8d587.tar.gz sleepy-b53ed06f8bf5213b5b652ba0ac0761b1e3d8d587.tar.bz2 sleepy-b53ed06f8bf5213b5b652ba0ac0761b1e3d8d587.zip |
use http.Request
Diffstat (limited to 'core.go')
-rw-r--r-- | core.go | 38 |
1 files changed, 19 insertions, 19 deletions
@@ -1,40 +1,40 @@ package sleepy +import ( + "net/http" +) + type Resource interface { - Get() string - // Post - // Put - // Delete + Get() string } type Route struct { - resource Resource - path string + resource Resource + path string } func (route *Route) pathMatch(path string) bool { - return route.path == path + return route.path == path } type Api struct { - routes []Route + routes []Route } func (api *Api) matchResource(path string) Resource { - for _, route := range api.routes { - if route.pathMatch(path) { - return route.resource - } - } - return nil + 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) HandleRequest(request *http.Request) string { + resource := api.matchResource(request.URL.Path) + return resource.Get() } - func (api *Api) AddResource(resource Resource, path string) { - api.routes = append(api.routes, Route{resource, path}) + api.routes = append(api.routes, Route{resource, path}) } |