mirror of
https://github.com/go-kratos/kratos.git
synced 2025-01-10 00:29:01 +02:00
27 lines
582 B
Go
27 lines
582 B
Go
package metric
|
|
|
|
import "fmt"
|
|
|
|
// Iterator iterates the buckets within the window.
|
|
type Iterator struct {
|
|
count int
|
|
iteratedCount int
|
|
cur *Bucket
|
|
}
|
|
|
|
// Next returns true util all of the buckets has been iterated.
|
|
func (i *Iterator) Next() bool {
|
|
return i.count != i.iteratedCount
|
|
}
|
|
|
|
// Bucket gets current bucket.
|
|
func (i *Iterator) Bucket() Bucket {
|
|
if !(i.Next()) {
|
|
panic(fmt.Errorf("stat/metric: iteration out of range iteratedCount: %d count: %d", i.iteratedCount, i.count))
|
|
}
|
|
bucket := *i.cur
|
|
i.iteratedCount++
|
|
i.cur = i.cur.Next()
|
|
return bucket
|
|
}
|