Accept ConfigKit integers in module options
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user