refactor: remove unused bodylimit.formatSize function and test
This commit is contained in:
parent
596237e484
commit
e3c6cb61f0
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user