4

My test Handler code is here:

func defineHandler(w http.ResponseWriter, r *http.Request) {
    a := strconv.ParseInt(r.FormValue("aRows")[0:], 10, 64);
    b := r.FormValue("aRows");
    fmt.Fprintf(w, "aRows is: %s", b);
}

The error returned during the compile comes out as: "multiple-value strconv.ParseInt() in single-value context"

I believe it has to do with the format of information in the FormValue I just don't know how to alleviate that.

kristianp
  • 5,496
  • 37
  • 56
user2628946
  • 103
  • 2
  • 6

1 Answers1

6

It means that strconv.ParseInt has multiple return values (the int, and an error), so you need to do:

a, err := strconv.ParseInt(r.FormValue("aRows")[0:], 10, 64);
if err != nil {
  // handle the error in some way
}
Tyler
  • 21,762
  • 11
  • 61
  • 90
  • Not so embarassing. They *could* have designed the language so that your original code is correct. The `parseInt` in many languages is like that: If there's an error it throws an exception or returns `NaN` or something. Go is designed this way to urge you to think about errors and handle them. It takes some getting used to. – Tyler Oct 09 '13 at 16:47