SwaggerUriToStdHttpUri converts a swagger style path URI with parameters to a net/http ServeMux compatible path URI. Parameter names are sanitized to be valid Go identifiers, as required by ServeMux wildcard segments. Valid input parameters are: {param} {param*} {.param} {.param*} {;param} {;
(uri string)
| 641 | // {?param} |
| 642 | // {?param*} |
| 643 | func SwaggerUriToStdHttpUri(uri string) string { |
| 644 | // https://pkg.go.dev/net/http#hdr-Patterns-ServeMux |
| 645 | // The special wildcard {$} matches only the end of the URL. For example, the pattern "/{$}" matches only the path "/", whereas the pattern "/" matches every path. |
| 646 | if uri == "/" { |
| 647 | return "/{$}" |
| 648 | } |
| 649 | |
| 650 | return pathParamRE.ReplaceAllStringFunc(uri, func(match string) string { |
| 651 | sub := pathParamRE.FindStringSubmatch(match) |
| 652 | return "{" + SanitizeGoIdentifier(sub[1]) + "}" |
| 653 | }) |
| 654 | } |
| 655 | |
| 656 | // OrderedParamsFromUri returns the argument names, in order, in a given URI string, so for |
| 657 | // /path/{param1}/{.param2*}/{?param3}, it would return param1, param2, param3 |