本文整理匯總了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
}