我正试图使用GOLANG构建一个简单的Web应用程序。目标是,当用户勾选复选框时,它必须调用API端点;当用户取消勾选复选框时,它必须调用另一个API端点。以下是我在HTML中定义的表单:
action="p_up_dags/{{.}}"
。
PS: .Result
是字符串列表。{{ range .Result}}
<form action="/p_up_dags/{{.}}" method="POST">
<br> <input id={{.}} type="checkbox" name="{{.}}" value="{{.}}" > {{.}}
</form>
{{end}}
GOLANG代码:
func p_up_dags(w http.ResponseWriter, r *http.Request){
d_name = mux.Vars(r)["name"]
//do something to check if the checkbox is checked or not
//Something like this
if d_name is checked
{
//http.Get("blah/blah")
}
else
{
//http.Get("foo/foo")
}
}
func main(){
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/p_up_dags/{name}",p_up_dags)
}