Fix panic on routing with parameters

There is a bug on your `utils.getRegex`. The `strings.Split` there may return a first segment of empty string, please read the documentation of [strings.Split](https://golang.org/pkg/strings/#Split).

**Screenshot before this PR**

![](https://dev-to-uploads.s3.amazonaws.com/i/8cjq6caln2b09115laau.png)

**Screenshot after this PR**

![](https://dev-to-uploads.s3.amazonaws.com/i/a31qo84v6fjc93qmlg81.png)
pull/28/head
Gerasimos (Makis) Maropoulos 2020-02-04 13:15:24 +02:00 committed by GitHub
parent 15a94e2d5b
commit 68a4b40e51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 0 deletions

View File

@ -35,6 +35,9 @@ func getRegex(path string) (*regexp.Regexp, error) {
pattern := "^"
segments := strings.Split(path, "/")
for _, s := range segments {
if s == "" {
continue
}
if s[0] == ':' {
if strings.Contains(s, "?") {
pattern += "(?:/([^/]+?))?"