diff --git a/decor/counters.go b/decor/counters.go index b7efdbe..0420275 100644 --- a/decor/counters.go +++ b/decor/counters.go @@ -38,20 +38,26 @@ // pairFmt="%f / %f" output: "1.000000MB / 12.000000MB" // pairFmt="% f / % f" output: "1.000000 MB / 12.000000 MB" func Counters(unit interface{}, pairFmt string, wcc ...WC) Decorator { - if pairFmt == "" { - pairFmt = "% d / % d" - } - producer := func() DecorFunc { - switch unit.(type) { - case SizeB1024: + producer := func() DecorFunc { + switch unit.(type) { + case SizeB1024: + if pairFmt == "" { + pairFmt = "% d / % d" + } return func(s Statistics) string { return fmt.Sprintf(pairFmt, SizeB1024(s.Current), SizeB1024(s.Total)) } case SizeB1000: + if pairFmt == "" { + pairFmt = "% d / % d" + } return func(s Statistics) string { return fmt.Sprintf(pairFmt, SizeB1000(s.Current), SizeB1000(s.Total)) } default: + if pairFmt == "" { + pairFmt = "%d / %d" + } return func(s Statistics) string { return fmt.Sprintf(pairFmt, s.Current, s.Total) } @@ -94,20 +100,26 @@ // format="%f" output: "12.000000MiB" // format="% f" output: "12.000000 MiB" func Total(unit interface{}, format string, wcc ...WC) Decorator { - if format == "" { - format = "% d" - } - producer := func() DecorFunc { - switch unit.(type) { - case SizeB1024: + producer := func() DecorFunc { + switch unit.(type) { + case SizeB1024: + if format == "" { + format = "% d" + } return func(s Statistics) string { return fmt.Sprintf(format, SizeB1024(s.Total)) } case SizeB1000: + if format == "" { + format = "% d" + } return func(s Statistics) string { return fmt.Sprintf(format, SizeB1000(s.Total)) } default: + if format == "" { + format = "%d" + } return func(s Statistics) string { return fmt.Sprintf(format, s.Total) } @@ -150,20 +162,26 @@ // format="%f" output: "12.000000MiB" // format="% f" output: "12.000000 MiB" func Current(unit interface{}, format string, wcc ...WC) Decorator { - if format == "" { - format = "% d" - } - producer := func() DecorFunc { - switch unit.(type) { - case SizeB1024: + producer := func() DecorFunc { + switch unit.(type) { + case SizeB1024: + if format == "" { + format = "% d" + } return func(s Statistics) string { return fmt.Sprintf(format, SizeB1024(s.Current)) } case SizeB1000: + if format == "" { + format = "% d" + } return func(s Statistics) string { return fmt.Sprintf(format, SizeB1000(s.Current)) } default: + if format == "" { + format = "%d" + } return func(s Statistics) string { return fmt.Sprintf(format, s.Current) } @@ -206,20 +224,26 @@ // format="%f" output: "12.000000MiB" // format="% f" output: "12.000000 MiB" func InvertedCurrent(unit interface{}, format string, wcc ...WC) Decorator { - if format == "" { - format = "% d" - } - producer := func() DecorFunc { - switch unit.(type) { - case SizeB1024: + producer := func() DecorFunc { + switch unit.(type) { + case SizeB1024: + if format == "" { + format = "% d" + } return func(s Statistics) string { return fmt.Sprintf(format, SizeB1024(s.Total-s.Current)) } case SizeB1000: + if format == "" { + format = "% d" + } return func(s Statistics) string { return fmt.Sprintf(format, SizeB1000(s.Total-s.Current)) } default: + if format == "" { + format = "%d" + } return func(s Statistics) string { return fmt.Sprintf(format, s.Total-s.Current) } diff --git a/decor/speed.go b/decor/speed.go index 8919cc2..1ebc332 100644 --- a/decor/speed.go +++ b/decor/speed.go @@ -67,9 +67,6 @@ // unit=SizeB1000(0), format="%.1f" output: "1.0MB/s" // unit=SizeB1000(0), format="% .1f" output: "1.0 MB/s" func MovingAverageSpeed(unit interface{}, format string, average ewma.MovingAverage, wcc ...WC) Decorator { - if format == "" { - format = "% d" - } d := &movingAverageSpeed{ WC: initWC(wcc...), average: average, @@ -128,9 +125,6 @@ // unit=SizeB1000(0), format="%.1f" output: "1.0MB/s" // unit=SizeB1000(0), format="% .1f" output: "1.0 MB/s" func NewAverageSpeed(unit interface{}, format string, startTime time.Time, wcc ...WC) Decorator { - if format == "" { - format = "% d" - } d := &averageSpeed{ WC: initWC(wcc...), startTime: startTime, @@ -161,14 +155,23 @@ func chooseSpeedProducer(unit interface{}, format string) func(float64) string { switch unit.(type) { case SizeB1024: + if format == "" { + format = "% d" + } return func(speed float64) string { return fmt.Sprintf(format, FmtAsSpeed(SizeB1024(math.Round(speed)))) } case SizeB1000: + if format == "" { + format = "% d" + } return func(speed float64) string { return fmt.Sprintf(format, FmtAsSpeed(SizeB1000(math.Round(speed)))) } default: + if format == "" { + format = "%f" + } return func(speed float64) string { return fmt.Sprintf(format, speed) }