changed parameter identifier to brackets over a colon, is more compatable with OpenAPI

This commit is contained in:
Colin Henry 2022-08-20 13:43:39 -07:00
parent f9a712bc33
commit 086c404610
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
}
isParam := false
if strings.HasPrefix(seg, ":") {
if strings.HasPrefix(seg, "{") {
isParam = true
seg = strings.TrimPrefix(seg, ":")
seg = strings.Trim(seg, "{}")
}
if !isParam { // verbatim check
if strings.HasSuffix(seg, "...") {

View File

@ -116,11 +116,11 @@ var tests = []struct {
},
// path params
{
"/path-param/:id",
"/path-param/{id}",
"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{
"era": "60s",
"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{
"era": "60s",
"group": "beatles",