本文整理汇总了Golang中github.com/juju/juju/state.StringsWatcher类的典型用法代码示例。如果您正苦于以下问题:Golang StringsWatcher类的具体用法?Golang StringsWatcher怎么用?Golang StringsWatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StringsWatcher类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: watchOneMachineContainers
func (p *ProvisionerAPI) watchOneMachineContainers(arg params.WatchContainer) (params.StringsWatchResult, error) {
nothing := params.StringsWatchResult{}
canAccess, err := p.getAuthFunc()
if err != nil {
return nothing, common.ErrPerm
}
tag, err := names.ParseMachineTag(arg.MachineTag)
if err != nil {
return nothing, common.ErrPerm
}
if !canAccess(tag) {
return nothing, common.ErrPerm
}
machine, err := p.st.Machine(tag.Id())
if err != nil {
return nothing, err
}
var watch state.StringsWatcher
if arg.ContainerType != "" {
watch = machine.WatchContainers(instance.ContainerType(arg.ContainerType))
} else {
watch = machine.WatchAllContainers()
}
// Consume the initial event and forward it to the result.
if changes, ok := <-watch.Changes(); ok {
return params.StringsWatchResult{
StringsWatcherId: p.resources.Register(watch),
Changes: changes,
}, nil
}
return nothing, watcher.EnsureErr(watch)
}
开发者ID:bac,项目名称:juju,代码行数:32,代码来源:provisioner.go
示例2: assertChange
func assertChange(c *gc.C, w state.StringsWatcher) {
select {
case <-w.Changes():
return
case <-time.After(coretesting.LongWait):
c.Fatalf("no changes on watcher")
}
}
开发者ID:bac,项目名称:juju,代码行数:8,代码来源:server_test.go
示例3: watchAttachments
func (s *StorageProvisionerAPI) watchAttachments(
args params.Entities,
watchEnvironAttachments func() state.StringsWatcher,
watchMachineAttachments func(names.MachineTag) state.StringsWatcher,
parseAttachmentIds func([]string) ([]params.MachineStorageId, error),
) (params.MachineStorageIdsWatchResults, error) {
canAccess, err := s.getScopeAuthFunc()
if err != nil {
return params.MachineStorageIdsWatchResults{}, common.ServerError(common.ErrPerm)
}
results := params.MachineStorageIdsWatchResults{
Results: make([]params.MachineStorageIdsWatchResult, len(args.Entities)),
}
one := func(arg params.Entity) (string, []params.MachineStorageId, 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 = watchMachineAttachments(tag)
} else {
w = watchEnvironAttachments()
}
if stringChanges, ok := <-w.Changes(); ok {
changes, err := parseAttachmentIds(stringChanges)
if err != nil {
w.Stop()
return "", nil, err
}
return s.resources.Register(w), changes, nil
}
return "", nil, watcher.EnsureErr(w)
}
for i, arg := range args.Entities {
var result params.MachineStorageIdsWatchResult
id, changes, err := one(arg)
if err != nil {
result.Error = common.ServerError(err)
} else {
result.MachineStorageIdsWatcherId = id
result.Changes = changes
}
results.Results[i] = result
}
return results, nil
}
开发者ID:imoapps,项目名称:juju,代码行数:47,代码来源:storageprovisioner.go
注:本文中的github.com/juju/juju/state.StringsWatcher类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论