Skip to content

Commit

Permalink
Merge pull request #7 from fulldump/feature/add-path-handlers
Browse files Browse the repository at this point in the history
Add path handlers to Context
  • Loading branch information
fulldump committed Feb 12, 2016
2 parents c7ea69b + 1274c92 commit 164f525
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ func (a *Api) ServeHTTP(w http.ResponseWriter, r *http.Request) {
parts = parts[:last]
}

// Calculate PathHttp and PathHandler
c.PathHandlers = a.Prefix

// Search the right node
current := a.Root
for _, part := range parts {
Expand All @@ -67,11 +70,13 @@ func (a *Api) ServeHTTP(w http.ResponseWriter, r *http.Request) {
for _, child := range current.Children {
if is_parameter(child.Path) {
c.Parameter = part
c.PathHandlers += "/" + child.Path
found = true
current = child
break
} else if part == child.Path {
c.Parameter = ""
c.PathHandlers += "/" + part
found = true
current = child
break
Expand All @@ -81,6 +86,7 @@ func (a *Api) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if found {
push_interceptors(current, c)
} else {
c.PathHandlers = "<Handler404>"
run_handler_in_context(a.Handler404, c)
return
}
Expand All @@ -97,6 +103,7 @@ func (a *Api) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

c.PathHandlers = "<Handler405>"
run_handler_in_context(a.Handler405, c)
}

Expand Down
1 change: 1 addition & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Context struct {
LastError *ContextError
Scope map[string]interface{}
Interceptors []*Interceptor
PathHandlers string
}

type ContextError struct {
Expand Down

0 comments on commit 164f525

Please sign in to comment.