Accept ConfigKit integers in module options

This commit is contained in:
2026-09-13 16:41:14 +00:00
parent cf17dd7bd0
commit d770e19c17
7 changed files with 72 additions and 4 deletions

View File

@@ -69,3 +69,22 @@ func RejectUnknownOptions(options map[string]any, allowed ...string) error {
}
return fmt.Errorf("unknown options %q", unknown)
}
// IntOption accepts the two integer representations admitted at the module
// boundary: native int values from programmatic bindings and int64 values from
// ConfigKit dynamic option maps. Callers remain responsible for their own
// domain constraints.
func IntOption(value any) (int, bool) {
switch typed := value.(type) {
case int:
return typed, true
case int64:
converted := int(typed)
if int64(converted) != typed {
return 0, false
}
return converted, true
default:
return 0, false
}
}