primeiro commit
This commit is contained in:
23
internal/probe/humanize.go
Normal file
23
internal/probe/humanize.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package probe
|
||||
|
||||
import "fmt"
|
||||
|
||||
// HumanizeBitsPerSecond formats a bit rate as kilobit, megabit, or gigabit.
|
||||
func HumanizeBitsPerSecond(bitsPerSecond float64) string {
|
||||
const (
|
||||
kilobit = 1000
|
||||
megabit = 1000 * kilobit
|
||||
gigabit = 1000 * megabit
|
||||
)
|
||||
|
||||
switch {
|
||||
case bitsPerSecond >= gigabit:
|
||||
return fmt.Sprintf("%.2f Gbit/s", bitsPerSecond/gigabit)
|
||||
case bitsPerSecond >= megabit:
|
||||
return fmt.Sprintf("%.2f Mbit/s", bitsPerSecond/megabit)
|
||||
case bitsPerSecond >= kilobit:
|
||||
return fmt.Sprintf("%.2f kbit/s", bitsPerSecond/kilobit)
|
||||
default:
|
||||
return fmt.Sprintf("%.0f bit/s", bitsPerSecond)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user