本文整理汇总了Golang中io.Reader.seconds方法的典型用法代码示例。如果您正苦于以下问题:Golang Reader.seconds方法的具体用法?Golang Reader.seconds怎么用?Golang Reader.seconds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.Reader
的用法示例。
在下文中一共展示了Reader.seconds方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: parseDensity
// wanted format:
// Nov 25 23:05:18.250: INFO: densityN-X Pods: 12000 out of 12000 created, 1012 running,
// 23 pending, 10965 waiting, 0 inactive, 0 terminating, 0 unknown, 0 runningButNotReady
func parseDensity(r io.Reader) (results []densityResult) {
densityFormat := "Pods: %d out of %d created, %d running, %d pending, %d waiting, %s"
//10 seconds interval
interval := 10
seconds := interval
br := bufio.NewReader(r)
for {
var r densityResult
var garbageString string
bytes, err := br.ReadBytes('\n')
if err != nil {
if err != io.EOF {
panic(err)
}
break
}
line := strings.TrimSpace(string(bytes[:len(bytes)-1]))
if !strings.HasSuffix(line, "runningButNotReady") {
continue
}
pi := strings.Index(line, "Pods")
if pi == -1 {
fmt.Fprintln(os.Stderr, "Bad density format: cannot find Pods")
os.Exit(1)
}
line = line[pi:]
_, err = fmt.Sscanf(line, densityFormat, &r.created, &totalPods, &r.running,
&r.pending, &r.waiting, &garbageString)
if err != nil {
fmt.Fprintln(os.Stderr, "Bad density format:", err)
os.Exit(1)
}
r.seconds = seconds
seconds += interval
results = append(results, r)
}
return results
}