在我的 golang 应用程序中,我根据表单输入将一些全局变量设置为 true,然后发现它们在后续函数中使用时已更改为 false。问题,在 golang 中声明和设置布尔值的正确方法是什么?
var withKetchup bool
var withMustard bool
func orderProcess(w http.ResponseWriter, r *http.Request){
r.ParseForm()
withKetchup := r.FormValue("withKetchup") //set to true (in form js form selection)
withMustard := r.FormValue("withMustard") //set to true
code omitted ///
}
func prepareOrder(){
code omitted//
fmt.Println(withKetchup, withMustard) //both are false even though initially set to true
if withKetchup == true && withMustard == true{
}else {
}
}
慕容3067478
相关分类