refactor: remove unused bodylimit.formatSize function and test

This commit is contained in:
xfy 2026-06-03 13:48:10 +08:00
parent 596237e484
commit e3c6cb61f0
2 changed files with 0 additions and 49 deletions

View File

@ -276,30 +276,4 @@ func ParseSize(sizeStr string) (int64, error) {
return int64(value * multiplier), nil
}
// formatSize 将字节数格式化为人类可读的字符串。
//
// 根据大小自动选择合适的单位b、kb、mb、gb
//
// 参数:
// - size: 字节数
//
// 返回值:
// - string: 格式化后的字符串,如 "1.00mb"、"10.00kb"
func formatSize(size int64) string {
const (
KB = 1024
MB = 1024 * KB
GB = 1024 * MB
)
switch {
case size >= GB:
return fmt.Sprintf("%.2fgb", float64(size)/GB)
case size >= MB:
return fmt.Sprintf("%.2fmb", float64(size)/MB)
case size >= KB:
return fmt.Sprintf("%.2fkb", float64(size)/KB)
default:
return fmt.Sprintf("%db", size)
}
}

View File

@ -48,29 +48,6 @@ func TestParseSize(t *testing.T) {
}
}
// TestFormatSize 测试字节数格式化。
func TestFormatSize(t *testing.T) {
tests := []struct {
input int64
expected string
}{
{512, "512b"},
{1024, "1.00kb"},
{1024 * 1024, "1.00mb"},
{1024 * 1024 * 1024, "1.00gb"},
{1536, "1.50kb"},
}
for _, tt := range tests {
t.Run(formatSize(tt.input), func(t *testing.T) {
got := formatSize(tt.input)
if got != tt.expected {
t.Errorf("formatSize(%d) = %s, want %s", tt.input, got, tt.expected)
}
})
}
}
// TestNew 测试创建中间件。
func TestNew(t *testing.T) {
tests := []struct {