Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add path handlers to Context #7

Merged
merged 1 commit into from
Feb 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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