html - 如何在 Golang 中将 HTML 表单值转换为 int

标签 html go forms typeconverter strconv

我的测试处理程序代码在这里:

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);
}

编译过程中返回的错误如下: “单值上下文中的多值 strconv.ParseInt()”

我认为这与 FormValue 中的信息格式有关,我只是不知道如何缓解这种情况。

最佳答案

意思是strconv.ParseInt有多个返回值(int 和一个错误),因此您需要执行以下操作:

a, err := strconv.ParseInt(r.FormValue("aRows")[0:], 10, 64);
if err != nil {
  // handle the error in some way
}

关于html - 如何在 Golang 中将 HTML 表单值转换为 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19239890/

相关文章:

javascript - Angular 5 包含 javascript 文件

html - 如何将 3 个框居中以匹配屏幕分辨率?

php - 如何从下拉列表中获取值并将其以不同的排列插入到MySQL表中?

javascript - 为什么我的表单水印脚本不再起作用?

json - Go 是否正确地将 float64 编码为 JSON?

javascript - GravityForms - gform_post_render 检查是否已提交?

javascript - Div 元素周围的语法荧光笔

html - 导航栏扩展的页面加载 - 已检查 "collapse in"

go - 关闭在服务器端发送但客户端仍然连接

json - 如何解析golang中的json数组?