MCPcopy Create free account
hub / github.com/MengMengCode/GetRealityDomain / FormatBytes

Function FormatBytes

utils.go:401–412  ·  view source on GitHub ↗

FormatBytes 格式化字节数为人类可读的格式

(bytes int64)

Source from the content-addressed store, hash-verified

399
400// FormatBytes 格式化字节数为人类可读的格式
401func FormatBytes(bytes int64) string {
402 const unit = 1024
403 if bytes < unit {
404 return fmt.Sprintf("%d B", bytes)
405 }
406 div, exp := int64(unit), 0
407 for n := bytes / unit; n >= unit; n /= unit {
408 div *= unit
409 exp++
410 }
411 return fmt.Sprintf("%.1f %cB", float64(bytes)/float64(div), "KMGTPE"[exp])
412}
413
414// IsPrivateIP 检查IP是否为私有地址
415func IsPrivateIP(ip net.IP) bool {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected