Codebase list golang-github-vbauerster-mpb / 3ee6888
SpeedFormatter Vladimir Bauer 6 years ago
1 changed file(s) with 5 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
88 "github.com/VividCortex/ewma"
99 )
1010
11 type speedType struct {
11 // SpeedFormatter is wrapper for SizeB1024 and SizeB1000 to format value as speed/s.
12 type SpeedFormatter struct {
1213 fmt.Formatter
1314 }
1415
15 func (self *speedType) Format(st fmt.State, verb rune) {
16 func (self *SpeedFormatter) Format(st fmt.State, verb rune) {
1617 self.Formatter.Format(st, verb)
1718 io.WriteString(st, "/s")
1819 }
182183 switch unit {
183184 case UnitKiB:
184185 return func(speed float64) string {
185 return fmt.Sprintf(format, &speedType{SizeB1024(math.Round(speed))})
186 return fmt.Sprintf(format, &SpeedFormatter{SizeB1024(math.Round(speed))})
186187 }
187188 case UnitKB:
188189 return func(speed float64) string {
189 return fmt.Sprintf(format, &speedType{SizeB1000(math.Round(speed))})
190 return fmt.Sprintf(format, &SpeedFormatter{SizeB1000(math.Round(speed))})
190191 }
191192 default:
192193 return func(speed float64) string {