2023-06-07 12:10:05 +05:30
|
|
|
package formatter
|
|
|
|
|
|
|
|
|
|
type Formatter interface {
|
|
|
|
|
Format(value float64, unit string) string
|
2023-08-16 14:22:40 +05:30
|
|
|
|
|
|
|
|
Name() string
|
2023-06-07 12:10:05 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
DurationFormatter = NewDurationFormatter()
|
|
|
|
|
BoolFormatter = NewBoolFormatter()
|
|
|
|
|
PercentFormatter = NewPercentFormatter()
|
|
|
|
|
NoneFormatter = NewNoneFormatter()
|
|
|
|
|
DataFormatter = NewDataFormatter()
|
|
|
|
|
DataRateFormatter = NewDataRateFormatter()
|
|
|
|
|
ThroughputFormatter = NewThroughputFormatter()
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func FromUnit(u string) Formatter {
|
|
|
|
|
switch u {
|
2025-08-20 11:04:50 +07:00
|
|
|
case "ns", "us", "µs", "ms", "s", "m", "h", "d", "min":
|
2023-06-07 12:10:05 +05:30
|
|
|
return DurationFormatter
|
2025-08-20 11:04:50 +07:00
|
|
|
case "bytes", "decbytes", "bits", "decbits", "kbytes", "decKbytes", "deckbytes", "mbytes", "decMbytes", "decmbytes", "gbytes", "decGbytes", "decgbytes", "tbytes", "decTbytes", "dectbytes", "pbytes", "decPbytes", "decpbytes", "By", "kBy", "MBy", "GBy", "TBy", "PBy":
|
2023-06-07 12:10:05 +05:30
|
|
|
return DataFormatter
|
2025-08-20 11:04:50 +07:00
|
|
|
case "binBps", "Bps", "binbps", "bps", "KiBs", "Kibits", "KBs", "Kbits", "MiBs", "Mibits", "MBs", "Mbits", "GiBs", "Gibits", "GBs", "Gbits", "TiBs", "Tibits", "TBs", "Tbits", "PiBs", "Pibits", "PBs", "Pbits", "By/s", "kBy/s", "MBy/s", "GBy/s", "TBy/s", "PBy/s", "bit/s", "kbit/s", "Mbit/s", "Gbit/s", "Tbit/s", "Pbit/s":
|
2023-06-07 12:10:05 +05:30
|
|
|
return DataRateFormatter
|
2025-08-20 11:04:50 +07:00
|
|
|
case "percent", "percentunit", "%":
|
2023-06-07 12:10:05 +05:30
|
|
|
return PercentFormatter
|
|
|
|
|
case "bool", "bool_yes_no", "bool_true_false", "bool_1_0":
|
|
|
|
|
return BoolFormatter
|
2025-08-20 11:04:50 +07:00
|
|
|
case "cps", "ops", "reqps", "rps", "wps", "iops", "cpm", "opm", "rpm", "wpm", "{count}/s", "{ops}/s", "{req}/s", "{read}/s", "{write}/s", "{iops}/s", "{count}/min", "{ops}/min", "{read}/min", "{write}/min":
|
2023-06-07 12:10:05 +05:30
|
|
|
return ThroughputFormatter
|
|
|
|
|
default:
|
|
|
|
|
return NoneFormatter
|
|
|
|
|
}
|
|
|
|
|
}
|