Skip to content

Commit

Permalink
added dot prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
matryer committed Apr 16, 2018
1 parent a8517f3 commit fd5c9b5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
13 changes: 7 additions & 6 deletions way.go
Expand Up @@ -39,7 +39,7 @@ func (r *Router) Handle(method, pattern string, handler http.Handler) {
method: strings.ToLower(method),
segs: r.pathSegments(pattern),
handler: handler,
prefix: strings.HasSuffix(pattern, "/"),
prefix: strings.HasSuffix(pattern, "/") || strings.HasSuffix(pattern, "..."),
}
r.routes = append(r.routes, route)
}
Expand Down Expand Up @@ -69,11 +69,7 @@ func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
// Param gets the path parameter from the specified Context.
// Returns an empty string if the parameter was not found.
func Param(ctx context.Context, param string) string {
v := ctx.Value(wayContextKey(param))
if v == nil {
return ""
}
vStr, ok := v.(string)
vStr, ok := ctx.Value(wayContextKey(param)).(string)
if !ok {
return ""
}
Expand Down Expand Up @@ -101,6 +97,11 @@ func (r *route) match(ctx context.Context, router *Router, segs []string) (conte
seg = strings.TrimPrefix(seg, ":")
}
if !isParam { // verbatim check
if strings.HasSuffix(seg, "...") {
if strings.HasPrefix(segs[i], seg[:len(seg)-3]) {
return ctx, true
}
}
if seg != segs[i] {
return nil, false
}
Expand Down
8 changes: 8 additions & 0 deletions way_test.go
Expand Up @@ -106,6 +106,14 @@ var tests = []struct {
"GET", "/not-prefix",
"GET", "/not-prefix/anything/else", false, nil,
},
{
"GET", "/prefixdots...",
"GET", "/prefixdots/anything/else", true, nil,
},
{
"GET", "/prefixdots...",
"GET", "/prefixdots", true, nil,
},
// path params
{
"GET", "/path-param/:id",
Expand Down

0 comments on commit fd5c9b5

Please sign in to comment.