當前位置: 首頁>>代碼示例>>Golang>>正文


Golang State.LatestPlaceholderCharm方法代碼示例

本文整理匯總了Golang中github.com/wallyworld/core/state.State.LatestPlaceholderCharm方法的典型用法代碼示例。如果您正苦於以下問題:Golang State.LatestPlaceholderCharm方法的具體用法?Golang State.LatestPlaceholderCharm怎麽用?Golang State.LatestPlaceholderCharm使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/wallyworld/core/state.State的用法示例。


在下文中一共展示了State.LatestPlaceholderCharm方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: fetchAllServicesAndUnits

// fetchAllServicesAndUnits returns a map from service name to service,
// a map from service name to unit name to unit, and a map from base charm URL to latest URL.
func fetchAllServicesAndUnits(
    st *state.State, unitMatcher unitMatcher) (
    map[string]*state.Service, map[string]map[string]*state.Unit, map[charm.URL]string, error) {

    svcMap := make(map[string]*state.Service)
    unitMap := make(map[string]map[string]*state.Unit)
    latestCharms := make(map[charm.URL]string)
    services, err := st.AllServices()
    if err != nil {
        return nil, nil, nil, err
    }
    for _, s := range services {
        units, err := s.AllUnits()
        if err != nil {
            return nil, nil, nil, err
        }
        svcUnitMap := make(map[string]*state.Unit)
        for _, u := range units {
            if !unitMatcher.matchUnit(u) {
                continue
            }
            svcUnitMap[u.Name()] = u
        }
        if unitMatcher.matchesAny() || len(svcUnitMap) > 0 {
            unitMap[s.Name()] = svcUnitMap
            svcMap[s.Name()] = s
            // Record the base URL for the service's charm so that
            // the latest store revision can be looked up.
            charmURL, _ := s.CharmURL()
            if charmURL.Schema == "cs" {
                latestCharms[*charmURL.WithRevision(-1)] = ""
            }
        }
    }
    for baseURL, _ := range latestCharms {
        ch, err := st.LatestPlaceholderCharm(&baseURL)
        if errors.IsNotFound(err) {
            continue
        }
        if err != nil {
            return nil, nil, nil, err
        }
        latestCharms[baseURL] = ch.String()
    }
    return svcMap, unitMap, latestCharms, nil
}
開發者ID:jameinel,項目名稱:core,代碼行數:48,代碼來源:status.go


注:本文中的github.com/wallyworld/core/state.State.LatestPlaceholderCharm方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。