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

75 lines
2.0 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"
"external-resource-schema/example/internal"
"github.com/pulumi/pulumi-random/sdk/v4/go/random"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
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 {
Name *random.RandomPet `pulumi:"name"`
}
type ArgFunctionResult struct {
Age *int `pulumi:"age"`
}
func ArgFunctionOutput(ctx *pulumi.Context, args ArgFunctionOutputArgs, opts ...pulumi.InvokeOption) ArgFunctionResultOutput {
return pulumi.ToOutputWithContext(context.Background(), args).
ApplyT(func(v interface{}) (ArgFunctionResult, error) {
args := v.(ArgFunctionArgs)
r, err := ArgFunction(ctx, &args, opts...)
[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
var s ArgFunctionResult
if r != nil {
s = *r
}
return s, err
}).(ArgFunctionResultOutput)
}
type ArgFunctionOutputArgs struct {
Name random.RandomPetInput `pulumi:"name"`
}
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) Age() pulumi.IntPtrOutput {
return o.ApplyT(func(v ArgFunctionResult) *int { return v.Age }).(pulumi.IntPtrOutput)
}
func init() {
pulumi.RegisterOutputType(ArgFunctionResultOutput{})
}