From 6c0775ba59fa02b0bbc9c15dfc3e817f705a12f7 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Tue, 29 Aug 2023 20:35:04 -0400 Subject: [PATCH] engine: resources: Consider passing in funcs if possible Let this sit in the test resource for now. --- engine/resources/test.go | 7 +++++++ lang/types/value.go | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/engine/resources/test.go b/engine/resources/test.go index f986abeb..a65de215 100644 --- a/engine/resources/test.go +++ b/engine/resources/test.go @@ -86,6 +86,9 @@ type TestRes struct { AnotherStr string `lang:"anotherstr" yaml:"anotherstr"` + // Func1 passes the value 42 to the input and returns a string. + Func1 func(int) string `lang:"func1" yaml:"func1"` + ValidateBool bool `lang:"validatebool" yaml:"validate_bool"` // set to true to cause a validate error ValidateError string `lang:"validateerror" yaml:"validate_error"` // set to cause a validate error AlwaysGroup bool `lang:"alwaysgroup" yaml:"always_group"` // set to true to cause auto grouping @@ -187,6 +190,10 @@ func (obj *TestRes) CheckApply(ctx context.Context, apply bool) (bool, error) { obj.init.Logf("%s: AnotherStr: %v", obj, obj.AnotherStr) + if obj.Func1 != nil { + obj.init.Logf("%s: Func1: %v", obj, obj.Func1(42)) + } + // send hello := obj.SendValue if err := obj.init.Send(&TestSends{ diff --git a/lang/types/value.go b/lang/types/value.go index 4dc7c958..89adaa39 100644 --- a/lang/types/value.go +++ b/lang/types/value.go @@ -440,7 +440,7 @@ func Into(v Value, rv reflect.Value) error { return Into(v.V, rv) default: - return fmt.Errorf("cannot Into() %+v of type %s into %s", v, v.Type(), typ) + return fmt.Errorf("cannot Into() %+v of type (%T) %s into %s", v, v, v.Type(), typ) } }