Skip to content

Commit 234cefe

Browse files
Merge pull request #28 from jumppad-labs/erik/add-bool-func-return
make it possible to return booleans from custom funcs
2 parents ec44b5e + 472adc8 commit 234cefe

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

functions.go

+10
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ func createCtyFunctionFromGoFunc(f interface{}) (function.Function, error) {
8282
fallthrough
8383
case reflect.Uint:
8484
outParam = function.StaticReturnType(cty.Number)
85+
case reflect.Bool:
86+
outParam = function.StaticReturnType(cty.Bool)
8587
default:
8688
return function.Function{}, fmt.Errorf("type %v is not a valid cyt type, only primative types like string and basic numbers are supported", rf.Out(0).Kind())
8789
}
@@ -130,6 +132,8 @@ func createCtyFunctionFromGoFunc(f interface{}) (function.Function, error) {
130132
val, _ := bf.Float64()
131133
in = append(in, reflect.ValueOf(float64(val)))
132134
}
135+
case cty.Bool:
136+
in = append(in, reflect.ValueOf(a.True()))
133137
}
134138
}
135139

@@ -177,6 +181,12 @@ func createCtyFunctionFromGoFunc(f interface{}) (function.Function, error) {
177181
return cty.NumberFloatVal(out[0].Float()), out[1].Interface().(error)
178182
}
179183
}
184+
case cty.Bool:
185+
if out[1].Interface() == nil {
186+
return cty.BoolVal(out[0].Bool()), nil
187+
} else {
188+
return cty.BoolVal(out[0].Bool()), out[1].Interface().(error)
189+
}
180190
}
181191

182192
return cty.NullVal(retType), nil

0 commit comments

Comments
 (0)