pulumi/tests/testdata/codegen/output-funcs/go/mypkg/funcWithAllOptionalInputs.go

88 lines
2.7 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 mypkg
import (
"context"
"reflect"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/pulumi/pulumi/sdk/v3/go/pulumix"
2023-06-14 16:34:49 +00:00
"output-funcs/mypkg/internal"
)
// Check codegen of functions with all optional inputs.
func FuncWithAllOptionalInputs(ctx *pulumi.Context, args *FuncWithAllOptionalInputsArgs, opts ...pulumi.InvokeOption) (*FuncWithAllOptionalInputsResult, error) {
2023-06-14 16:34:49 +00:00
opts = internal.PkgInvokeDefaultOpts(opts)
var rv FuncWithAllOptionalInputsResult
err := ctx.Invoke("mypkg::funcWithAllOptionalInputs", args, &rv, opts...)
if err != nil {
return nil, err
}
return &rv, nil
}
type FuncWithAllOptionalInputsArgs struct {
// Property A
A *string `pulumi:"a"`
// Property B
B *string `pulumi:"b"`
}
type FuncWithAllOptionalInputsResult struct {
R string `pulumi:"r"`
}
func FuncWithAllOptionalInputsOutput(ctx *pulumi.Context, args FuncWithAllOptionalInputsOutputArgs, opts ...pulumi.InvokeOption) FuncWithAllOptionalInputsResultOutput {
return pulumi.ToOutputWithContext(context.Background(), args).
ApplyT(func(v interface{}) (FuncWithAllOptionalInputsResult, error) {
args := v.(FuncWithAllOptionalInputsArgs)
r, err := FuncWithAllOptionalInputs(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 FuncWithAllOptionalInputsResult
if r != nil {
s = *r
}
return s, err
}).(FuncWithAllOptionalInputsResultOutput)
}
type FuncWithAllOptionalInputsOutputArgs struct {
// Property A
A pulumi.StringPtrInput `pulumi:"a"`
// Property B
B pulumi.StringPtrInput `pulumi:"b"`
}
func (FuncWithAllOptionalInputsOutputArgs) ElementType() reflect.Type {
return reflect.TypeOf((*FuncWithAllOptionalInputsArgs)(nil)).Elem()
}
type FuncWithAllOptionalInputsResultOutput struct{ *pulumi.OutputState }
func (FuncWithAllOptionalInputsResultOutput) ElementType() reflect.Type {
return reflect.TypeOf((*FuncWithAllOptionalInputsResult)(nil)).Elem()
}
func (o FuncWithAllOptionalInputsResultOutput) ToFuncWithAllOptionalInputsResultOutput() FuncWithAllOptionalInputsResultOutput {
return o
}
func (o FuncWithAllOptionalInputsResultOutput) ToFuncWithAllOptionalInputsResultOutputWithContext(ctx context.Context) FuncWithAllOptionalInputsResultOutput {
return o
}
func (o FuncWithAllOptionalInputsResultOutput) ToOutput(ctx context.Context) pulumix.Output[FuncWithAllOptionalInputsResult] {
return pulumix.Output[FuncWithAllOptionalInputsResult]{
OutputState: o.OutputState,
}
}
func (o FuncWithAllOptionalInputsResultOutput) R() pulumi.StringOutput {
return o.ApplyT(func(v FuncWithAllOptionalInputsResult) string { return v.R }).(pulumi.StringOutput)
}
func init() {
pulumi.RegisterOutputType(FuncWithAllOptionalInputsResultOutput{})
}