I am new to the go lang and am sure I am missing something very basic but since I have scoured the web and have not found anything to help me understand my problem I thought I would post it here. Essentially what I am trying to do is a simple conversion from a string to an int. The string arrives as a numerical value represented as a string (ie. "1"); I would like to change it to the int equivalent so I can use it in a switch ... case. I have tried both Atoi and parseInt and both fail with the same error:
./test.go:1765: cannot use v (type []string) as type string in argument to strconv.Atoi
I tried to assign it to a string first and then pass it in to Atoi but it still didn't work.
Here is the code:
r.ParseForm()
for k, v := range r.Form {
if k == "StartPicker" && strings.Join(v, "") != "" {
layout := dateLayout
startDate, err = time.Parse(layout, strings.Join(v, ""))
if err != nil {
fmt.Println("time.Parse() err:", err)
}
} else if k == "EndPicker" && strings.Join(v, "") != "" {
layout := dateLayout
endDate, err = time.Parse(layout, strings.Join(v, ""))
if err != nil {
fmt.Println("time.Parse() err:", err)
}
} else {
fmt.Printf("k = %s
", k)
if k == "FilterType" {
fmt.Printf("this is the variable filterType: %s
", v)
time, sqlFilter := strconv.Atoi(v)
if err != nil {
// handle error
fmt.Println("Atoi broken err:", err)
}
} else if k == "MSISDN" {
msisdn := v
}
}
}