Plugins: add bool2int conversion (#29995)

This commit is contained in:
andig 2026-05-18 11:10:49 +02:00 • committed by GitHub
parent fed967856f
commit 1e40a2aa9d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -71,3 +71,23 @@ func (o *convertPlugin) IntSetter(param string) (func(int64) error, error) {
return nil, fmt.Errorf("convert: invalid conversion: %s", o.Convert)
}
}
var _ BoolSetter = (*convertPlugin)(nil)
func (o *convertPlugin) BoolSetter(param string) (func(bool) error, error) {
switch o.Convert {
case "bool2int":
set, err := o.Set.IntSetter(o.ctx, param)
return func(val bool) error {
var i int64
if val {
i = 1
}
return set(i)
}, err
default:
return nil, fmt.Errorf("convert: invalid conversion: %s", o.Convert)
}
}