Skip to content

Commit e19b6ef

Browse files
committed
clean code
1 parent fa87a96 commit e19b6ef

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

router.go

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -237,41 +237,43 @@ func (router *Router) matchAndParse(requestUrl string, path string) (paramsMapTy
237237

238238
for _, str := range res {
239239

240-
if str != "" {
241-
r := []byte(str)
240+
if str == "" {
241+
continue
242+
}
242243

243-
if string(r[0]) == "{" && string(r[len(r)-1]) == "}" {
244-
matchStr := string(r[1 : len(r)-1])
245-
res := strings.Split(matchStr, ":")
244+
r := []byte(str)
246245

247-
matchName = append(matchName, res[0])
246+
if string(r[0]) == "{" && string(r[len(r)-1]) == "}" {
247+
matchStr := string(r[1 : len(r)-1])
248+
res := strings.Split(matchStr, ":")
248249

249-
sTemp = sTemp + "/" + "(" + res[1] + ")"
250-
} else if string(r[0]) == ":" {
251-
matchStr := string(r)
252-
res := strings.Split(matchStr, ":")
253-
matchName = append(matchName, res[1])
250+
matchName = append(matchName, res[0])
254251

255-
if res[1] == idKey {
256-
sTemp = sTemp + "/" + "(" + idPattern + ")"
257-
} else {
258-
sTemp = sTemp + "/" + "(" + defaultPattern + ")"
259-
}
252+
sTemp = sTemp + "/" + "(" + res[1] + ")"
253+
} else if string(r[0]) == ":" {
254+
matchStr := string(r)
255+
res := strings.Split(matchStr, ":")
256+
matchName = append(matchName, res[1])
257+
258+
if res[1] == idKey {
259+
sTemp = sTemp + "/" + "(" + idPattern + ")"
260260
} else {
261-
sTemp = sTemp + "/" + str
261+
sTemp = sTemp + "/" + "(" + defaultPattern + ")"
262262
}
263+
} else {
264+
sTemp = sTemp + "/" + str
263265
}
264266
}
265267

266268
pattern := sTemp
267269

268270
re := regexp.MustCompile(pattern)
269-
submatch := re.FindSubmatch([]byte(requestUrl))
271+
subMatch := re.FindSubmatch([]byte(requestUrl))
270272

271-
if submatch != nil {
272-
if string(submatch[0]) == requestUrl {
273-
submatch = submatch[1:]
274-
for k, v := range submatch {
273+
if subMatch != nil {
274+
if string(subMatch[0]) == requestUrl {
275+
subMatch = subMatch[1:]
276+
for k, v := range subMatch {
275277
matchParams[matchName[k]] = string(v)
276278
}
277279
return matchParams, true

0 commit comments

Comments
 (0)