该守则做了以下工作:
获取安装状态的数组,并提供一些总体状态,即数组上的字符串值overallstatus=error
overallstatus=running
overallstatus=installing。
我的问题是,是否有一个simpler/shorter写在go中?
func overallInstallationStatus(installStatus []apiv.Installstatus) string {
overallStatus := ""
for _, status := range installStatus {
switch status.ReleaseStatus {
case release.StatusFailed.String():
// If at least one installation is in failed, we consider the overallstatus to be in error state
overallStatus = "error"
case release.StatusDeployed.String():
// If no other status was found and there is at least one deployed chart, we consider it "running"
if overallStatus == "" {
overallStatus = "running"
}
default:
// All other statuses are considered to be "installing"
if overallStatus != release.StatusFailed.String() {
overallStatus = "installing"
}
}
}
return overallStatus
}发布于 2021-05-20 11:31:49
是的,它可以简化和缩短:
func overallInstallationStatus(installStatus []apiv.Installstatus) string {
overallStatus := "running"
for _, status := range installStatus {
switch status.ReleaseStatus {
case release.StatusFailed.String():
//If at least one installation is in failed, we consider the overallstatus to be in error state
return "error"
case release.StatusDeployed.String():
//If no other status was found and there is at least one deployed chart, we consider it "running"
continue
default:
//All other statuses are considered to be "installing"
overallStatus = "installing"
}
}
return overallStatus
}https://stackoverflow.com/questions/67619323
复制相似问题