在代码里面,我尝试做一些操作
is_html := false;
// Check, if HTMl is exist
for i := 0; i < len(modules_arr); i++ {
if modules_arr[i] == "html" { is_html := true }
}
if is_html ==true
{
fmt.Printf("%v", "asdasd")
}
但是我得到一个错误:
./api.go:26: missing condition in if statement
./api.go:26: is_html == true evaluated but not used
Error: process exited with code 2.
最佳答案
if 语句需要 { 在 go 中的同一行
这意味着你不能这样做
if is_html ==true
{
fmt.Printf("%v", "asdasd")
}
正确的代码是
if is_html ==true {
fmt.Printf("%v", "asdasd")
}
阅读http://golang.org/doc/effective_go.html#semicolons为了更好的理解
此外,如果检查 MyVal == true,您可以使用短版本:
if MyVal{
//do stuff
}
在您的情况下,正确的命名也是:IsHtml。您可以使用 golint 打印出样式错误:https://github.com/golang/lint
使用 golint 的示例:https://www.golangprograms.com/media/wysiwyg/name.JPG
关于go - == true 已评估但未使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22948567/