One approach is to loop through the possible values and add to the fragment along the way:
r.ParseForm()
var a []string
for i := 0; ; i++ {
key := fmt.Sprintf("status[%d]", i)
values := r.Form[key]
if len(values) == 0 {
break
}
a = append(a, values[i])
i++
}
If you have control over the query string, use this format:
site.com/?status=1&status=2&status=3&name=John
and get the state values using:
r.ParseForm()
a := r.Form["status"] // a is []string{"1", "2", "3"}
source
share