pulumi/tests/testdata/codegen/simple-resource-schema-cust.../go/example/argFunction.go

80 lines
2.2 KiB
Go
Raw Normal View History

// Code generated by test DO NOT EDIT.
// *** WARNING: Do not edit by hand unless you're certain you know what you are doing! ***
package example
import (
"context"
"reflect"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
2023-06-14 19:59:47 +00:00
"simple-resource-schema-custom-pypackage-name/example/internal"
)
func ArgFunction(ctx *pulumi.Context, args *ArgFunctionArgs, opts ...pulumi.InvokeOption) (*ArgFunctionResult, error) {
2023-06-14 16:34:49 +00:00
opts = internal.PkgInvokeDefaultOpts(opts)
var rv ArgFunctionResult
err := ctx.Invoke("example::argFunction", args, &rv, opts...)
if err != nil {
return nil, err
}
return &rv, nil
}
type ArgFunctionArgs struct {
Arg1 *Resource `pulumi:"arg1"`
}
type ArgFunctionResult struct {
Result *Resource `pulumi:"result"`
}
func ArgFunctionOutput(ctx *pulumi.Context, args ArgFunctionOutputArgs, opts ...pulumi.InvokeOption) ArgFunctionResultOutput {
return pulumi.ToOutputWithContext(context.Background(), args).
ApplyT(func(v interface{}) (ArgFunctionResultOutput, error) {
args := v.(ArgFunctionArgs)
opts = internal.PkgInvokeDefaultOpts(opts)
var rv ArgFunctionResult
secret, err := ctx.InvokePackageRaw("example::argFunction", args, &rv, "", opts...)
if err != nil {
return ArgFunctionResultOutput{}, err
[codegen/go] Update Go SDK function output to check for errors (#9274) * [codegen/go] Update Go SDK function output to check for errors Fixes https://github.com/pulumi/pulumi-aws/issues/1872. This should result in the following sample output in the Go SDK: ``` func GetPolicyDocumentOutput(ctx *pulumi.Context, args GetPolicyDocumentOutputArgs, opts ...pulumi.InvokeOption) GetPolicyDocumentResultOutput { return pulumi.ToOutputWithContext(context.Background(), args). ApplyT(func(v interface{}) (GetPolicyDocumentResult, error) { args := v.(GetPolicyDocumentArgs) r, err := GetPolicyDocument(ctx, &args, opts...) if err != nil { return nil, err } if r == nil { return nil, fmt.Errorf("expected either result or error to be nil, not both") } return *r, err }).(GetPolicyDocumentResultOutput) } ``` * Fix generated code panic on *nil (#9284) * [codegen/go] Update Go SDK function output to check for errors Fixes https://github.com/pulumi/pulumi-aws/issues/1872. This should result in the following sample output in the Go SDK: ``` func GetPolicyDocumentOutput(ctx *pulumi.Context, args GetPolicyDocumentOutputArgs, opts ...pulumi.InvokeOption) GetPolicyDocumentResultOutput { return pulumi.ToOutputWithContext(context.Background(), args). ApplyT(func(v interface{}) (GetPolicyDocumentResult, error) { args := v.(GetPolicyDocumentArgs) r, err := GetPolicyDocument(ctx, &args, opts...) if r != nil { s = *r } return s, err }).(GetPolicyDocumentResultOutput) } ``` * Alternate fix to safeguard dereferencing nil * Accept codegen changes in the test suite Co-authored-by: Guinevere Saenger <guinevere@pulumi.com> * Update CHANGELOG_PENDING.md Co-authored-by: Anton Tayanovskyy <anton@pulumi.com>
2022-03-25 03:11:53 +00:00
}
output := pulumi.ToOutput(rv).(ArgFunctionResultOutput)
if secret {
return pulumi.ToSecret(output).(ArgFunctionResultOutput), nil
}
return output, nil
}).(ArgFunctionResultOutput)
}
type ArgFunctionOutputArgs struct {
Arg1 ResourceInput `pulumi:"arg1"`
}
func (ArgFunctionOutputArgs) ElementType() reflect.Type {
return reflect.TypeOf((*ArgFunctionArgs)(nil)).Elem()
}
type ArgFunctionResultOutput struct{ *pulumi.OutputState }
func (ArgFunctionResultOutput) ElementType() reflect.Type {
return reflect.TypeOf((*ArgFunctionResult)(nil)).Elem()
}
func (o ArgFunctionResultOutput) ToArgFunctionResultOutput() ArgFunctionResultOutput {
return o
}
func (o ArgFunctionResultOutput) ToArgFunctionResultOutputWithContext(ctx context.Context) ArgFunctionResultOutput {
return o
}
func (o ArgFunctionResultOutput) Result() ResourceOutput {
return o.ApplyT(func(v ArgFunctionResult) *Resource { return v.Result }).(ResourceOutput)
}
func init() {
pulumi.RegisterOutputType(ArgFunctionResultOutput{})
}