utils.go: new function toInt() converts any(int64) to int
This commit is contained in:
parent
52fb398cd8
commit
5643a57bcc
10
utils.go
10
utils.go
@ -5,6 +5,7 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
@ -168,3 +169,12 @@ func CloneFilteredMap[K comparable, V any](source map[K]V, filter func(key K) (a
|
||||
dest := make(map[K]V, len(source))
|
||||
return CopyFilteredMap(dest, source, filter)
|
||||
}
|
||||
|
||||
func toInt(value any, description string) (i int, err error) {
|
||||
if valueInt64, ok := value.(int64); ok {
|
||||
i = int(valueInt64)
|
||||
} else {
|
||||
err = fmt.Errorf("%s expected integer, got %T (%v)", description, value, value)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user