github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/codegen/testing/test/testdata/output-funcs/go/mypkg/funcWithDefaultValue.go (about)

     1  // Code generated by test DO NOT EDIT.
     2  // *** WARNING: Do not edit by hand unless you're certain you know what you are doing! ***
     3  
     4  package mypkg
     5  
     6  import (
     7  	"context"
     8  	"reflect"
     9  
    10  	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    11  )
    12  
    13  // Check codegen of functions with default values.
    14  func FuncWithDefaultValue(ctx *pulumi.Context, args *FuncWithDefaultValueArgs, opts ...pulumi.InvokeOption) (*FuncWithDefaultValueResult, error) {
    15  	var rv FuncWithDefaultValueResult
    16  	err := ctx.Invoke("mypkg::funcWithDefaultValue", args.Defaults(), &rv, opts...)
    17  	if err != nil {
    18  		return nil, err
    19  	}
    20  	return &rv, nil
    21  }
    22  
    23  type FuncWithDefaultValueArgs struct {
    24  	A string  `pulumi:"a"`
    25  	B *string `pulumi:"b"`
    26  }
    27  
    28  // Defaults sets the appropriate defaults for FuncWithDefaultValueArgs
    29  func (val *FuncWithDefaultValueArgs) Defaults() *FuncWithDefaultValueArgs {
    30  	if val == nil {
    31  		return nil
    32  	}
    33  	tmp := *val
    34  	if isZero(tmp.B) {
    35  		b_ := "b-default"
    36  		tmp.B = &b_
    37  	}
    38  	return &tmp
    39  }
    40  
    41  type FuncWithDefaultValueResult struct {
    42  	R string `pulumi:"r"`
    43  }
    44  
    45  func FuncWithDefaultValueOutput(ctx *pulumi.Context, args FuncWithDefaultValueOutputArgs, opts ...pulumi.InvokeOption) FuncWithDefaultValueResultOutput {
    46  	return pulumi.ToOutputWithContext(context.Background(), args).
    47  		ApplyT(func(v interface{}) (FuncWithDefaultValueResult, error) {
    48  			args := v.(FuncWithDefaultValueArgs)
    49  			r, err := FuncWithDefaultValue(ctx, &args, opts...)
    50  			var s FuncWithDefaultValueResult
    51  			if r != nil {
    52  				s = *r
    53  			}
    54  			return s, err
    55  		}).(FuncWithDefaultValueResultOutput)
    56  }
    57  
    58  type FuncWithDefaultValueOutputArgs struct {
    59  	A pulumi.StringInput    `pulumi:"a"`
    60  	B pulumi.StringPtrInput `pulumi:"b"`
    61  }
    62  
    63  func (FuncWithDefaultValueOutputArgs) ElementType() reflect.Type {
    64  	return reflect.TypeOf((*FuncWithDefaultValueArgs)(nil)).Elem()
    65  }
    66  
    67  type FuncWithDefaultValueResultOutput struct{ *pulumi.OutputState }
    68  
    69  func (FuncWithDefaultValueResultOutput) ElementType() reflect.Type {
    70  	return reflect.TypeOf((*FuncWithDefaultValueResult)(nil)).Elem()
    71  }
    72  
    73  func (o FuncWithDefaultValueResultOutput) ToFuncWithDefaultValueResultOutput() FuncWithDefaultValueResultOutput {
    74  	return o
    75  }
    76  
    77  func (o FuncWithDefaultValueResultOutput) ToFuncWithDefaultValueResultOutputWithContext(ctx context.Context) FuncWithDefaultValueResultOutput {
    78  	return o
    79  }
    80  
    81  func (o FuncWithDefaultValueResultOutput) R() pulumi.StringOutput {
    82  	return o.ApplyT(func(v FuncWithDefaultValueResult) string { return v.R }).(pulumi.StringOutput)
    83  }
    84  
    85  func init() {
    86  	pulumi.RegisterOutputType(FuncWithDefaultValueResultOutput{})
    87  }