1 Commits

Author SHA1 Message Date
Colin Henry
086c404610 changed parameter identifier to brackets over a colon, is more compatable with OpenAPI 2022-08-20 13:43:39 -07:00
2 changed files with 5 additions and 5 deletions

View File

@@ -84,9 +84,9 @@ func (r *route) match(ctx context.Context, router *ServeMux, segs []string) (con
return nil, false return nil, false
} }
isParam := false isParam := false
if strings.HasPrefix(seg, ":") { if strings.HasPrefix(seg, "{") {
isParam = true isParam = true
seg = strings.TrimPrefix(seg, ":") seg = strings.Trim(seg, "{}")
} }
if !isParam { // verbatim check if !isParam { // verbatim check
if strings.HasSuffix(seg, "...") { if strings.HasSuffix(seg, "...") {

View File

@@ -116,11 +116,11 @@ var tests = []struct {
}, },
// path params // path params
{ {
"/path-param/:id", "/path-param/{id}",
"GET", "/path-param/123", true, map[string]string{"id": "123"}, "GET", "/path-param/123", true, map[string]string{"id": "123"},
}, },
{ {
"/path-params/:era/:group/:member", "/path-params/{era}/{group}/{member}",
"GET", "/path-params/60s/beatles/lennon", true, map[string]string{ "GET", "/path-params/60s/beatles/lennon", true, map[string]string{
"era": "60s", "era": "60s",
"group": "beatles", "group": "beatles",
@@ -128,7 +128,7 @@ var tests = []struct {
}, },
}, },
{ {
"/path-params-prefix/:era/:group/:member/", "/path-params-prefix/{era}/{group}/{member}/",
"GET", "/path-params-prefix/60s/beatles/lennon/yoko", true, map[string]string{ "GET", "/path-params-prefix/60s/beatles/lennon/yoko", true, map[string]string{
"era": "60s", "era": "60s",
"group": "beatles", "group": "beatles",