Set Function Return
Set function return expects an unordered, unique collection of single element type value from function logic. Set values in function logic with a Go slice of an appropriate type to match the element type []T
or the framework set type.
Function Definition
Use the function.SetReturn
type in the function definition.
The ElementType
field must be defined, which represents the single framework value type of every element of the set. An element type may itself contain further collection or object types, if necessary.
In this example, a function definition includes a set of string return:
func (f ExampleFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { resp.Definition = function.Definition{ // ... other Definition fields ... Return: function.SetReturn{ ElementType: types.StringType, // ... potentially other SetReturn fields ... }, }}
Custom Types
You may want to build your own data value and type implementations to allow your provider to combine validation and other behaviors into a reusable bundle. This helps avoid duplication and ensures consistency. These implementations use the CustomType
field in the return type.
Refer to Custom Types for further details on creating provider-defined types and values.
Documentation
Return documentation is expected in the top-level function documentation. Refer to function documentation for information about the Summary
, Description
, and MarkdownDescription
fields available.
Setting Return Data
The function implementation documentation covers the general methods for setting function return data in function logic.
When setting the value for this return:
- If
CustomType
is set, use its associated value type. - Otherwise, use a Go slice of an appropriate type to match the element type
[]T
or framework set type.
In this example, a function defines a set of string return and sets its value:
func (f ExampleFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { resp.Definition = function.Definition{ // ... other Definition fields ... Return: function.SetReturn{ ElementType: types.StringType, }, }} func (f ExampleFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { // ... other logic ... // hardcoded value for example brevity result := []string{"one", "two"} resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, &result))}