From 086c404610a580500464afce9c58dbaee5cfc65e Mon Sep 17 00:00:00 2001 From: Colin Henry Date: Sat, 20 Aug 2022 13:43:39 -0700 Subject: [PATCH] changed parameter identifier to brackets over a colon, is more compatable with OpenAPI --- net/http/mux.go | 4 ++-- net/http/mux_test.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/net/http/mux.go b/net/http/mux.go index 8e6e394..cda99fa 100644 --- a/net/http/mux.go +++ b/net/http/mux.go @@ -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, "...") { diff --git a/net/http/mux_test.go b/net/http/mux_test.go index 85602c7..2c2b311 100644 --- a/net/http/mux_test.go +++ b/net/http/mux_test.go @@ -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",