Files
3ybactuk-marketplace-go-ser…/loms/internal/infra/tools/safecast.go
Никита Шубин 77ed9fcf85 [hw-4] add postgres db
2025-06-26 12:08:46 +00:00

20 lines
400 B
Go

package tools
import (
"fmt"
"math"
)
func SafeCastInt64ToUInt32(num int64) (uint32, error) {
if num < 0 {
return 0, fmt.Errorf("tried casting signed negative number to unsigned number")
}
if num > math.MaxUint32 {
return 0, fmt.Errorf("tried casting larger number than uint32 can store")
}
// the bounds are checked, and cast should be safe.
return uint32(num), nil // #nosec G115
}