为什么在此代码的函数结尾处缺少返回值? [英] Why am I getting a missing return at end of function in this code?
本文介绍了为什么在此代码的函数结尾处缺少返回值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
func getKeyNameFromDeploymentAndSubnet(subnetType SubnetType, deploymentType DeploymentType, keyNameMap map[SubnetType]string) string {
if (deploymentType == NoDeployment || deploymentType == PDBAWindows || deploymentType == AgentDeployment) {
return keyNameMap[subnetType]
}
else if (deploymentType == AnsibleDeployment) {
return "bar"
}
return "foo"
}
在第一个if
语句中,在函数错误结束时出现缺少返回的错误.如果删除else if
语句,则不会出现此错误.我要去哪里错了?
In the first if
statement, I get an error of missing return at end of function error. I don't get this error if I remove the else if
statement. Where am I going wrong?
推荐答案
您会收到此错误,因为else
语句必须与第一个条件的结尾}
在同一行.
You get this error because else
statement must be on the same line as the closing }
of the first condition.
func getKeyNameFromDeploymentAndSubnet(subnetType SubnetType, deploymentType DeploymentType, keyNameMap map[SubnetType]string) string {
if deploymentType == NoDeployment || deploymentType == PDBAWindows || deploymentType == AgentDeployment {
return keyNameMap[subnetType]
} else if deploymentType == AnsibleDeployment {
return "bar"
}
return "foo"
}
这篇关于为什么在此代码的函数结尾处缺少返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文