types
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
type Function interface {
|
||||
Name() string
|
||||
Types() []string
|
||||
Types() map[string]string
|
||||
Definition() string
|
||||
IsAsync() bool
|
||||
Arguments() []reflect.Type
|
||||
@@ -25,7 +25,7 @@ type functionImpl[A Args, R any] struct {
|
||||
name string
|
||||
fn GoFunc[A, R]
|
||||
definition string
|
||||
types []string
|
||||
types map[string]string
|
||||
isAsync bool
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ func (b *functionImpl[A, R]) Name() string {
|
||||
return b.name
|
||||
}
|
||||
|
||||
func (b *functionImpl[A, R]) Types() []string {
|
||||
func (b *functionImpl[A, R]) Types() map[string]string {
|
||||
return b.types
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ func (b *functionImpl[A, R]) Function() any {
|
||||
}
|
||||
|
||||
func (b *functionImpl[A, R]) Arguments() []reflect.Type {
|
||||
// Collect Argument Types
|
||||
var allTypes []reflect.Type
|
||||
|
||||
rType := reflect.TypeFor[A]()
|
||||
@@ -73,17 +74,19 @@ func (b *functionImpl[A, R]) CallGeneric(ctx context.Context, allArgs []any) (ze
|
||||
for i := range min(aVal.NumField(), len(allArgs)) {
|
||||
field := aVal.Field(i)
|
||||
|
||||
// Validate Field is Settable
|
||||
if !field.CanSet() {
|
||||
return zeroR, errors.New("cannot set field")
|
||||
}
|
||||
|
||||
// Validate and Set Field Value
|
||||
argVal := reflect.ValueOf(allArgs[i])
|
||||
if !argVal.Type().AssignableTo(field.Type()) {
|
||||
return zeroR, errors.New("cannot assign field")
|
||||
}
|
||||
|
||||
field.Set(argVal)
|
||||
}
|
||||
|
||||
// Execute Function
|
||||
return b.fn(ctx, fnArgs)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user