Skip to content

Commit

Permalink
Merge pull request #18 from palestamp/master
Browse files Browse the repository at this point in the history
Handle nil RequestCtx inside getValue
  • Loading branch information
buaazp committed Dec 13, 2016
2 parents e26e6aa + 5893f38 commit 7778060
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
package fasthttprouter

import (
"github.com/valyala/fasthttp"
"strings"
"unicode"
"unicode/utf8"
"github.com/valyala/fasthttp"
)

func min(a, b int) int {
Expand Down Expand Up @@ -361,7 +361,10 @@ walk: // outer loop for walking the tree
end++
}

ctx.SetUserValue(n.path[1:], path[:end])
// handle calls to Router.allowed method with nil context
if ctx != nil {
ctx.SetUserValue(n.path[1:], path[:end])
}

// we need to go deeper!
if end < len(path) {
Expand All @@ -388,8 +391,10 @@ walk: // outer loop for walking the tree
return

case catchAll:
// save param value
ctx.SetUserValue(n.path[2:], path)
if ctx != nil {
// save param value
ctx.SetUserValue(n.path[2:], path)
}
handle = n.handle
return

Expand Down

0 comments on commit 7778060

Please sign in to comment.