Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert an HTML form value into an int in Golang

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.

like image 651
user2628946 Avatar asked Sep 18 '25 20:09

user2628946


1 Answers

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
}
like image 176
Tyler Avatar answered Sep 20 '25 10:09

Tyler