返回总体状态的Go函数
该代码执行以下操作:返回总体状态的Go函数,go,Go,该代码执行以下操作: 获取安装状态数组,并提供一些总体状态,即字符串值 数组上的循环,如果有一个安装条目是错误的,所有的安装都被认为是错误的,并且返回 如果正在运行overallstatus=running 否则overallstatus=安装 我的问题是,是否有一个更简单/更短的来用围棋写 func overallInstallationStatus(installStatus []apiv.Installstatus) string { overallStatus := "
overallstatus=running
overallstatus=安装
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
}
是的,它可以简化和缩短:
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
}
如果列表中至少有一个正在运行且没有错误,则状态为
正在运行
,或者对于正在运行
,所有应在没有错误的情况下运行?我只是想澄清一下我的想法answer@nipuna-如果出现错误,状态应为error,oterwise installing或runningyes,这是明确的。什么是运行状态
?至少on运行时没有错误,或者全部运行时没有错误?@nipuna全部运行时没有错误好的,我已经编辑了答案。这可以简化。请在那里查一下