Simplify module cleanup paths

This commit is contained in:
2026-08-09 02:40:25 +00:00
parent d28d1062e0
commit 0546f6eb4f
5 changed files with 21 additions and 101 deletions

View File

@@ -2,10 +2,7 @@ package units
import (
"context"
"encoding/json"
"fmt"
"math"
"strconv"
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
@@ -158,67 +155,11 @@ func nonNegativeIntOption(name string, value any) (int, error) {
}
func intOption(name string, value any) (int, error) {
switch typed := value.(type) {
case int:
return typed, nil
case int8:
return int(typed), nil
case int16:
return int(typed), nil
case int32:
return int(typed), nil
case int64:
if typed > maxInt() || typed < minInt() {
return 0, chunkerErrorf("%s is outside supported integer range", name)
}
return int(typed), nil
case uint:
if uint64(typed) > uint64(maxInt()) {
return 0, chunkerErrorf("%s is outside supported integer range", name)
}
return int(typed), nil
case uint8:
return int(typed), nil
case uint16:
return int(typed), nil
case uint32:
if uint64(typed) > uint64(maxInt()) {
return 0, chunkerErrorf("%s is outside supported integer range", name)
}
return int(typed), nil
case uint64:
if typed > uint64(maxInt()) {
return 0, chunkerErrorf("%s is outside supported integer range", name)
}
return int(typed), nil
case float64:
if typed != math.Trunc(typed) {
return 0, chunkerErrorf("%s must be an integer", name)
}
if typed > float64(maxInt()) || typed < float64(minInt()) {
return 0, chunkerErrorf("%s is outside supported integer range", name)
}
return int(typed), nil
case json.Number:
parsed, err := typed.Int64()
if err != nil {
return 0, chunkerErrorf("%s must be an integer", name)
}
if parsed > maxInt() || parsed < minInt() {
return 0, chunkerErrorf("%s is outside supported integer range", name)
}
return int(parsed), nil
default:
got, ok := value.(int)
if !ok {
return 0, chunkerErrorf("%s must be an integer", name)
}
}
func maxInt() int64 {
return int64(1<<(strconv.IntSize-1) - 1)
}
func minInt() int64 {
return -maxInt() - 1
return got, nil
}
func chunkerErrorf(format string, args ...any) error {