logging and diagnostic features added
Some checks failed
CI / test-build (push) Failing after 2m11s

This commit is contained in:
2025-12-15 00:45:14 +07:00
parent 3e64de18ed
commit df475bc85e
26 changed files with 5878 additions and 91 deletions

View File

@@ -0,0 +1,58 @@
package httpapp
import (
"fmt"
"strconv"
"strings"
)
// parseSizeString parses a human-readable size string to bytes
func (a *App) parseSizeString(sizeStr string) (uint64, error) {
sizeStr = strings.TrimSpace(strings.ToUpper(sizeStr))
if sizeStr == "" {
return 0, fmt.Errorf("size cannot be empty")
}
// Extract number and unit
var numStr string
var unit string
for i, r := range sizeStr {
if r >= '0' && r <= '9' {
numStr += string(r)
} else {
unit = sizeStr[i:]
break
}
}
if numStr == "" {
return 0, fmt.Errorf("invalid size format: no number found")
}
num, err := strconv.ParseUint(numStr, 10, 64)
if err != nil {
return 0, fmt.Errorf("invalid size number: %w", err)
}
// Convert to bytes based on unit
multiplier := uint64(1)
switch unit {
case "":
multiplier = 1
case "K", "KB":
multiplier = 1024
case "M", "MB":
multiplier = 1024 * 1024
case "G", "GB":
multiplier = 1024 * 1024 * 1024
case "T", "TB":
multiplier = 1024 * 1024 * 1024 * 1024
case "P", "PB":
multiplier = 1024 * 1024 * 1024 * 1024 * 1024
default:
return 0, fmt.Errorf("invalid size unit: %s (allowed: K, M, G, T, P)", unit)
}
return num * multiplier, nil
}