This commit is contained in:
2026-01-29 10:07:33 -05:00
parent 234c4718a4
commit 0d97f20e79
16 changed files with 929 additions and 646 deletions

View File

@@ -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)
}