Update parseGetParams to call strconv.Atoi when params are valid

This commit is contained in:
onee-only 2024-03-04 21:06:09 +09:00 committed by Junegunn Choi
parent 52210a57f0
commit 61bc129e1d

View File

@ -236,17 +236,17 @@ func parseGetParams(query string) getParams {
for _, pair := range strings.Split(query, "&") { for _, pair := range strings.Split(query, "&") {
parts := strings.SplitN(pair, "=", 2) parts := strings.SplitN(pair, "=", 2)
if len(parts) == 2 { if len(parts) == 2 {
val, err := strconv.Atoi(parts[1])
if err != nil {
continue
}
switch parts[0] { switch parts[0] {
case "limit": case "limit", "offset":
if val, err := strconv.Atoi(parts[1]); err == nil {
if parts[0] == "limit" {
params.limit = val params.limit = val
case "offset": } else {
params.offset = val params.offset = val
} }
} }
} }
}
}
return params return params
} }