亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

返回整體狀態的 Go 函數

返回整體狀態的 Go 函數

Go
慕田峪9158850 2022-08-30 21:58:47
該代碼執行以下操作:獲取安裝狀態數組并提供一些整體狀態,即字符串值循環在陣列上,如果其中一個安裝條目是錯誤的,則所有安裝都視為錯誤并返回overallstatus=error如果一個正在運行overallstatus=running否則overallstatus=installing我的問題是,如果有更簡單/更短的寫法?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}
查看完整描述

1 回答

?
www說

TA貢獻1775條經驗 獲得超8個贊

是的,它可以簡化和縮短:


 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

 }


查看完整回答
反對 回復 2022-08-30
  • 1 回答
  • 0 關注
  • 115 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號