首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >返回整体状态的Go函数

返回整体状态的Go函数
EN

Stack Overflow用户
提问于 2021-05-20 11:18:13
回答 1查看 52关注 0票数 0

该守则做了以下工作:

获取安装状态的数组,并提供一些总体状态,即数组上的字符串值overallstatus=error

  • if

  • 循环,如果有一个安装条目是错误,则所有安装都认为是错误并返回overallstatus=running

  • otherwise overallstatus=installing

我的问题是,是否有一个simpler/shorter写在go中?

代码语言:javascript
复制
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
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-20 11:31:49

是的,它可以简化和缩短:

代码语言:javascript
复制
 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
 }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67619323

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档