本文整理汇总了Golang中github.com/ubuntu-core/snappy/progress.Meter.Spin方法的典型用法代码示例。如果您正苦于以下问题:Golang Meter.Spin方法的具体用法?Golang Meter.Spin怎么用?Golang Meter.Spin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ubuntu-core/snappy/progress.Meter
的用法示例。
在下文中一共展示了Meter.Spin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: parseSIProgress
func parseSIProgress(pb progress.Meter, stdout io.Reader) error {
if pb == nil {
pb = &progress.NullProgress{}
}
scanner := bufio.NewScanner(stdout)
// s-i is funny, total changes during the runs
total := 0.0
pb.Start("ubuntu-core", 100)
for scanner.Scan() {
if os.Getenv("SNAPPY_DEBUG") != "" {
fmt.Println(scanner.Text())
}
jsonStream := strings.NewReader(scanner.Text())
dec := json.NewDecoder(jsonStream)
var genericData genericJSON
if err := dec.Decode(&genericData); err != nil {
// we ignore invalid json here and continue
// the parsing if s-i-cli or ubuntu-core-upgrader
// output something unexpected (like stray debug
// output or whatnot)
continue
}
switch {
case genericData.Type == "spinner":
pb.Spin(genericData.Message)
case genericData.Type == "error":
return fmt.Errorf("error from %s: %s", systemImageCli, genericData.Message)
case genericData.Type == "progress":
if total != genericData.Total {
total = genericData.Total
pb.SetTotal(total)
}
pb.Set(genericData.Now)
}
}
// ugly: avoid Spin() artifacts
pb.Notify("\nApply done")
if err := scanner.Err(); err != nil {
return err
}
return nil
}