Go · Level 1 Project

Project: Query String Parser

Build a URL query string parser in Go: split on &, cut each pair at the first =, and collect repeated keys into a map of slices, the way net/url's ParseQuery does (without URL decoding).

  • strings.Cut splits at the first separator
  • append works on a nil slice
  • map[string][]string for repeated keys

strings.Cut(s, "=") splits at the first = only, and append works on a nil slice, so m[k] = append(m[k], v) collects repeated keys. Trap: strings.Split(p, "=") breaks values that contain =.

k, v, _ := strings.Cut("q=a=b", "=")
// k is "q", v is "a=b"
m := map[string][]string{}
m["tag"] = append(m["tag"], "go")

Write ParseQuery(q string) map[string][]string: split on &, skip empty parts, cut each part at the first = (a key alone gets ""), and collect repeated keys in order. Example: ParseQuery("page=2&tag=go&tag=web") → map[page:[2] tag:[go web]].

solution.go
Test Suites Pending
Output