migrate
This commit is contained in:
@@ -17,9 +17,6 @@ func (t TestArgs) Validate() error {
|
||||
}
|
||||
|
||||
func TestAsyncFunction(t *testing.T) {
|
||||
registryMutex.RLock()
|
||||
defer registryMutex.RUnlock()
|
||||
|
||||
RegisterAsyncFunction("testAsync", func(_ context.Context, args TestArgs) (string, error) {
|
||||
return "result: " + args.Field1, nil
|
||||
})
|
||||
|
||||
@@ -11,6 +11,7 @@ type Function interface {
|
||||
Types() []string
|
||||
Definition() string
|
||||
IsAsync() bool
|
||||
Arguments() []reflect.Type
|
||||
Call(context.Context, []any) (any, error)
|
||||
}
|
||||
|
||||
@@ -48,6 +49,17 @@ func (b *functionImpl[A, R]) Function() any {
|
||||
return b.fn
|
||||
}
|
||||
|
||||
func (b *functionImpl[A, R]) Arguments() []reflect.Type {
|
||||
var allTypes []reflect.Type
|
||||
|
||||
rType := reflect.TypeFor[A]()
|
||||
for i := range rType.NumField() {
|
||||
allTypes = append(allTypes, rType.Field(i).Type)
|
||||
}
|
||||
|
||||
return allTypes
|
||||
}
|
||||
|
||||
func (b *functionImpl[A, R]) Call(ctx context.Context, allArgs []any) (any, error) {
|
||||
return b.CallGeneric(ctx, allArgs)
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ func (t TestBasicArgs) Validate() error { return nil }
|
||||
|
||||
func TestBasicType(t *testing.T) {
|
||||
resetRegistry()
|
||||
RegisterFunction[TestBasicArgs, string]("basic", func(ctx context.Context, args TestBasicArgs) (string, error) {
|
||||
RegisterFunction("basic", func(ctx context.Context, args TestBasicArgs) (string, error) {
|
||||
return args.Name, nil
|
||||
})
|
||||
|
||||
@@ -47,7 +47,7 @@ func (t TestComplexArgs) Validate() error { return nil }
|
||||
|
||||
func TestComplexTypes(t *testing.T) {
|
||||
resetRegistry()
|
||||
RegisterFunction[TestComplexArgs, bool]("complex", func(ctx context.Context, args TestComplexArgs) (bool, error) {
|
||||
RegisterFunction("complex", func(ctx context.Context, args TestComplexArgs) (bool, error) {
|
||||
return args.Flag, nil
|
||||
})
|
||||
|
||||
@@ -66,7 +66,7 @@ func (t TestNestedArgs) Validate() error { return nil }
|
||||
|
||||
func TestNestedStruct(t *testing.T) {
|
||||
resetRegistry()
|
||||
RegisterFunction[TestNestedArgs, string]("nested", func(ctx context.Context, args TestNestedArgs) (string, error) {
|
||||
RegisterFunction("nested", func(ctx context.Context, args TestNestedArgs) (string, error) {
|
||||
return args.User.FirstName, nil
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user