mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-10-25 05:12:04 +00:00
Some checks are pending
CI / go-test (push) Waiting to run
CI / postgres-durable-first (push) Waiting to run
CI / codegen (push) Waiting to run
CI / govulncheck (push) Waiting to run
CI / race (push) Waiting to run
CI / node-e2e (push) Waiting to run
CI / fuzz-smoke (push) Waiting to run
CI / golangci (push) Waiting to run
CI / frontend (push) Waiting to run
CodeQL Advanced / Analyze (go) (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
Release 3X-UI / build (386) (push) Waiting to run
Release 3X-UI / build (amd64) (push) Waiting to run
Release 3X-UI / build (arm64) (push) Waiting to run
Release 3X-UI / build (armv5) (push) Waiting to run
Release 3X-UI / build (armv6) (push) Waiting to run
Release 3X-UI / build (armv7) (push) Waiting to run
Release 3X-UI / build (s390x) (push) Waiting to run
Release 3X-UI / Build for Windows (push) Waiting to run
Release 3X-UI / Publish rolling dev release (push) Blocked by required conditions
Co-authored-by: Javier Guerrero <javier.guerrero@github.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
16 lines
421 B
Go
16 lines
421 B
Go
package common
|
|
|
|
import "strconv"
|
|
|
|
// FormatTraffic formats traffic bytes into human-readable units (B, KB, MB, GB, TB, PB).
|
|
func FormatTraffic(trafficBytes int64) string {
|
|
units := []string{"B", "KB", "MB", "GB", "TB", "PB"}
|
|
unitIndex := 0
|
|
size := float64(trafficBytes)
|
|
|
|
for size >= 1024 && unitIndex < len(units)-1 {
|
|
size /= 1024
|
|
unitIndex++
|
|
}
|
|
return strconv.FormatFloat(size, 'f', 2, 64) + units[unitIndex]
|
|
}
|