Skip to content
Myr

Update parseGetParams to call strconv.Atoi when params are valid

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by onee-only · committed by Junegunn Choi · parent 52210a5 · Browse files · 1 file+8 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+8 added−8 removed

  • other:+8 added−8 removed

1 file+8 added−8 removed

modified:src/server.go+8 added-8 removed
234 unmodified lines
235 params := getParams{limit: 100, offset: 0}236 for _, pair := range strings.Split(query, "&") {237 parts := strings.SplitN(pair, "=", 2)238 if len(parts) == 2 {239 val, err := strconv.Atoi(parts[1])240 if err != nil {241 continue242 }239 switch parts[0] {244 case "limit":245 params.limit = val246 case "offset":247 params.offset = val240 case "limit", "offset":241 if val, err := strconv.Atoi(parts[1]); err == nil {242 if parts[0] == "limit" {243 params.limit = val244 } else {245 params.offset = val246 }247 }248 }249 }250 }251 return params
1 unmodified line