FormatBytes 格式化字节数为人类可读的格式
(bytes int64)
| 399 | |
| 400 | // FormatBytes 格式化字节数为人类可读的格式 |
| 401 | func 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是否为私有地址 |
| 415 | func IsPrivateIP(ip net.IP) bool { |
nothing calls this directly
no outgoing calls
no test coverage detected