本文整理汇总了Golang中github.com/juju/juju/apiserver/params.StringsWatchResult.Changes方法的典型用法代码示例。如果您正苦于以下问题:Golang StringsWatchResult.Changes方法的具体用法?Golang StringsWatchResult.Changes怎么用?Golang StringsWatchResult.Changes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/apiserver/params.StringsWatchResult
的用法示例。
在下文中一共展示了StringsWatchResult.Changes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: WatchEnvironMachines
// WatchEnvironMachines returns a StringsWatcher that notifies of
// changes to the life cycles of the top level machines in the current
// environment.
func (e *EnvironMachinesWatcher) WatchEnvironMachines() (params.StringsWatchResult, error) {
result := params.StringsWatchResult{}
if !e.authorizer.AuthEnvironManager() {
return result, ErrPerm
}
watch := e.st.WatchEnvironMachines()
// Consume the initial event and forward it to the result.
if changes, ok := <-watch.Changes(); ok {
result.StringsWatcherId = e.resources.Register(watch)
result.Changes = changes
} else {
err := watcher.EnsureErr(watch)
return result, fmt.Errorf("cannot obtain initial environment machines: %v", err)
}
return result, nil
}
示例2: watchStorageEntities
func (s *StorageProvisionerAPI) watchStorageEntities(
args params.Entities,
watchEnvironStorage func() state.StringsWatcher,
watchMachineStorage func(names.MachineTag) state.StringsWatcher,
) (params.StringsWatchResults, error) {
canAccess, err := s.getScopeAuthFunc()
if err != nil {
return params.StringsWatchResults{}, common.ServerError(common.ErrPerm)
}
results := params.StringsWatchResults{
Results: make([]params.StringsWatchResult, len(args.Entities)),
}
one := func(arg params.Entity) (string, []string, error) {
tag, err := names.ParseTag(arg.Tag)
if err != nil || !canAccess(tag) {
return "", nil, common.ErrPerm
}
var w state.StringsWatcher
if tag, ok := tag.(names.MachineTag); ok {
w = watchMachineStorage(tag)
} else {
w = watchEnvironStorage()
}
if changes, ok := <-w.Changes(); ok {
return s.resources.Register(w), changes, nil
}
return "", nil, watcher.EnsureErr(w)
}
for i, arg := range args.Entities {
var result params.StringsWatchResult
id, changes, err := one(arg)
if err != nil {
result.Error = common.ServerError(err)
} else {
result.StringsWatcherId = id
result.Changes = changes
}
results.Results[i] = result
}
return results, nil
}