gpt4 book ai didi

go - 为什么我在此代码中的函数末尾缺少返回值?

转载 作者:IT王子 更新时间:2023-10-29 02:29:13 25 4
gpt4 key购买 nike

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 语句,我不会收到此错误。我哪里错了?

最佳答案

您收到此错误是因为 else 语句必须与第一个条件的结束 } 在同一行。

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"
}

关于go - 为什么我在此代码中的函数末尾缺少返回值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45071362/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com