Codebase list golang-github-vbauerster-mpb / fd4c44c
don't check verb count user may want to add '%%' in format string Vladimir Bauer 3 years ago
2 changed file(s) with 0 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
11
22 import (
33 "fmt"
4 "strings"
54 )
65
76 // CountersNoUnit is a wrapper around Counters with no unit param.
4039 func Counters(unit interface{}, pairFmt string, wcc ...WC) Decorator {
4140 if pairFmt == "" {
4241 pairFmt = "%d / %d"
43 } else if strings.Count(pairFmt, "%") != 2 {
44 panic("expected pairFmt with exactly 2 verbs")
4542 }
4643 producer := func() DecorFunc {
4744 switch unit.(type) {
9895 func Total(unit interface{}, format string, wcc ...WC) Decorator {
9996 if format == "" {
10097 format = "%d"
101 } else if strings.Count(format, "%") != 1 {
102 panic("expected format with exactly 1 verb")
10398 }
10499 producer := func() DecorFunc {
105100 switch unit.(type) {
156151 func Current(unit interface{}, format string, wcc ...WC) Decorator {
157152 if format == "" {
158153 format = "%d"
159 } else if strings.Count(format, "%") != 1 {
160 panic("expected format with exactly 1 verb")
161154 }
162155 producer := func() DecorFunc {
163156 switch unit.(type) {
214207 func InvertedCurrent(unit interface{}, format string, wcc ...WC) Decorator {
215208 if format == "" {
216209 format = "%d"
217 } else if strings.Count(format, "%") != 1 {
218 panic("expected format with exactly 1 verb")
219210 }
220211 producer := func() DecorFunc {
221212 switch unit.(type) {
33 "fmt"
44 "io"
55 "math"
6 "strings"
76 "time"
87
98 "github.com/VividCortex/ewma"
6968 func MovingAverageSpeed(unit interface{}, format string, average ewma.MovingAverage, wcc ...WC) Decorator {
7069 if format == "" {
7170 format = "%.0f"
72 } else if strings.Count(format, "%") != 1 {
73 panic("expected format with exactly 1 verb")
7471 }
7572 d := &movingAverageSpeed{
7673 WC: initWC(wcc...),
132129 func NewAverageSpeed(unit interface{}, format string, startTime time.Time, wcc ...WC) Decorator {
133130 if format == "" {
134131 format = "%.0f"
135 } else if strings.Count(format, "%") != 1 {
136 panic("expected format with exactly 1 verb")
137132 }
138133 d := &averageSpeed{
139134 WC: initWC(wcc...),