本文整理匯總了Golang中launchpad/net/juju-core/state.State.AllServices方法的典型用法代碼示例。如果您正苦於以下問題:Golang State.AllServices方法的具體用法?Golang State.AllServices怎麽用?Golang State.AllServices使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類launchpad/net/juju-core/state.State
的用法示例。
在下文中一共展示了State.AllServices方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: fetchAllServicesAndUnits
// fetchAllServicesAndUnits returns a map from service name to service
// and a map from service name to unit name to unit.
func fetchAllServicesAndUnits(st *state.State, unitMatcher unitMatcher) (map[string]*state.Service, map[string]map[string]*state.Unit, error) {
svcMap := make(map[string]*state.Service)
unitMap := make(map[string]map[string]*state.Unit)
services, err := st.AllServices()
if err != nil {
return nil, nil, err
}
for _, s := range services {
units, err := s.AllUnits()
if err != nil {
return 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
}
}
return svcMap, unitMap, nil
}
示例2: fetchAllServices
// fetchAllServices returns a map representing a mapping of service
// names to services.
func fetchAllServices(st *state.State) (map[string]*state.Service, error) {
v := make(map[string]*state.Service)
services, err := st.AllServices()
if err != nil {
return nil, err
}
for _, s := range services {
v[s.Name()] = s
}
return v, nil
}
示例3: fetchAllServicesAndUnits
// fetchAllServicesAndUnits returns a map from service name to service
// and a map from service name to unit name to unit.
func fetchAllServicesAndUnits(st *state.State) (map[string]*state.Service, map[string]map[string]*state.Unit, error) {
svcMap := make(map[string]*state.Service)
unitMap := make(map[string]map[string]*state.Unit)
services, err := st.AllServices()
if err != nil {
return nil, nil, err
}
for _, s := range services {
svcMap[s.Name()] = s
units, err := s.AllUnits()
if err != nil {
return nil, nil, err
}
svcUnitMap := make(map[string]*state.Unit)
for _, u := range units {
svcUnitMap[u.Name()] = u
}
unitMap[s.Name()] = svcUnitMap
}
return svcMap, unitMap, nil
}