pulumi/pkg/codegen/internal/test/testdata/simple-methods-schema/go/example/foo.go
Pat Gavlin 52d01bb915
[codegen/go] Remove ResourcePtr input/output types (#8449)
These changes remove the `Ptr` variants of input/ouptut types for
resources. A `TPtr` input or output is normally generated for `T` if `T`
is present in an `optional(input(T))` or `optional(output(T))` and if
the Go representation for `T` is not nilable. The generation of `Ptr`
variants for resource types breaks the latter rule: the canonical
representation of a resource type named `Foo` is a pointer to a struct
type named `Foo` (i.e. `*Foo`). `Foo` itself is not a resource, as it
does not implement the Go `Resource` interface. Because this
representation already accommodates `nil` to indicate the lack of a
value, we need not generate `FooPtr{Input,Output}` types.

Besides being unnecessary, the implementation of `Ptr` types for
resources was incorrect. Rather than using `**Foo` as their element
type, these types use `*Foo`--identical to the element type used for
the normal input/output types. Furthermore, the generated code for
at least `FooOutput.ToFooPtrOutputWithContext` and `FooPtrOutput.Elem`
was incorrect, making these types virtually unusable in practice.

Finally, these `Ptr` types should never appear on input/output
properties in practice, as the logic we use to generate input and output
type references never generates them for `optional({input,output}(T)).
Instead, it generates references to the standard input/output types.

Though this is _technically_ a breaking change--it changes the set of
exported types for any package that defines resources--I believe that in
practice it will be invisible to users for the reasons stated above.
These types are not usable, and were never referenced.

This is preparatory work for #7943.
2021-11-23 10:24:56 -08:00

183 lines
5.3 KiB
Go

// *** WARNING: this file was generated by test. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
package example
import (
"context"
"reflect"
"github.com/pulumi/pulumi-random/sdk/v2/go/random"
"github.com/pulumi/pulumi/pkg/v3/codegen/internal/test/testdata/simple-methods-schema/go/example/nested"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
type Foo struct {
pulumi.ResourceState
}
// NewFoo registers a new resource with the given unique name, arguments, and options.
func NewFoo(ctx *pulumi.Context,
name string, args *FooArgs, opts ...pulumi.ResourceOption) (*Foo, error) {
if args == nil {
args = &FooArgs{}
}
var resource Foo
err := ctx.RegisterRemoteComponentResource("example::Foo", name, args, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
type fooArgs struct {
}
// The set of arguments for constructing a Foo resource.
type FooArgs struct {
}
func (FooArgs) ElementType() reflect.Type {
return reflect.TypeOf((*fooArgs)(nil)).Elem()
}
// A description of bar.
func (r *Foo) Bar(ctx *pulumi.Context, args *FooBarArgs) (FooBarResultOutput, error) {
out, err := ctx.Call("example::Foo/bar", args, FooBarResultOutput{}, r)
if err != nil {
return FooBarResultOutput{}, err
}
return out.(FooBarResultOutput), nil
}
type fooBarArgs struct {
Baz *nested.Baz `pulumi:"baz"`
BazPlain *nested.Baz `pulumi:"bazPlain"`
BazRequired nested.Baz `pulumi:"bazRequired"`
BoolValue *bool `pulumi:"boolValue"`
BoolValuePlain *bool `pulumi:"boolValuePlain"`
BoolValueRequired bool `pulumi:"boolValueRequired"`
Name *random.RandomPet `pulumi:"name"`
NamePlain *random.RandomPet `pulumi:"namePlain"`
NameRequired *random.RandomPet `pulumi:"nameRequired"`
StringValue *string `pulumi:"stringValue"`
StringValuePlain *string `pulumi:"stringValuePlain"`
StringValueRequired string `pulumi:"stringValueRequired"`
}
// The set of arguments for the Bar method of the Foo resource.
type FooBarArgs struct {
Baz nested.BazPtrInput
BazPlain *nested.BazArgs
BazRequired nested.BazInput
BoolValue pulumi.BoolPtrInput
BoolValuePlain *bool
BoolValueRequired pulumi.BoolInput
Name random.RandomPetInput
NamePlain *random.RandomPet
NameRequired random.RandomPetInput
StringValue pulumi.StringPtrInput
StringValuePlain *string
StringValueRequired pulumi.StringInput
}
func (FooBarArgs) ElementType() reflect.Type {
return reflect.TypeOf((*fooBarArgs)(nil)).Elem()
}
type FooBarResult struct {
SomeValue string `pulumi:"someValue"`
}
type FooBarResultOutput struct{ *pulumi.OutputState }
func (FooBarResultOutput) ElementType() reflect.Type {
return reflect.TypeOf((*FooBarResult)(nil)).Elem()
}
func (o FooBarResultOutput) SomeValue() pulumi.StringOutput {
return o.ApplyT(func(v FooBarResult) string { return v.SomeValue }).(pulumi.StringOutput)
}
func (r *Foo) Baz(ctx *pulumi.Context) error {
_, err := ctx.Call("example::Foo/baz", nil, pulumi.AnyOutput{}, r)
return err
}
// Do something with something else
func (r *Foo) GenerateKubeconfig(ctx *pulumi.Context, args *FooGenerateKubeconfigArgs) (FooGenerateKubeconfigResultOutput, error) {
out, err := ctx.Call("example::Foo/generateKubeconfig", args, FooGenerateKubeconfigResultOutput{}, r)
if err != nil {
return FooGenerateKubeconfigResultOutput{}, err
}
return out.(FooGenerateKubeconfigResultOutput), nil
}
type fooGenerateKubeconfigArgs struct {
BoolValue bool `pulumi:"boolValue"`
}
// The set of arguments for the GenerateKubeconfig method of the Foo resource.
type FooGenerateKubeconfigArgs struct {
BoolValue bool
}
func (FooGenerateKubeconfigArgs) ElementType() reflect.Type {
return reflect.TypeOf((*fooGenerateKubeconfigArgs)(nil)).Elem()
}
type FooGenerateKubeconfigResult struct {
Kubeconfig string `pulumi:"kubeconfig"`
}
type FooGenerateKubeconfigResultOutput struct{ *pulumi.OutputState }
func (FooGenerateKubeconfigResultOutput) ElementType() reflect.Type {
return reflect.TypeOf((*FooGenerateKubeconfigResult)(nil)).Elem()
}
func (o FooGenerateKubeconfigResultOutput) Kubeconfig() pulumi.StringOutput {
return o.ApplyT(func(v FooGenerateKubeconfigResult) string { return v.Kubeconfig }).(pulumi.StringOutput)
}
type FooInput interface {
pulumi.Input
ToFooOutput() FooOutput
ToFooOutputWithContext(ctx context.Context) FooOutput
}
func (*Foo) ElementType() reflect.Type {
return reflect.TypeOf((**Foo)(nil)).Elem()
}
func (i *Foo) ToFooOutput() FooOutput {
return i.ToFooOutputWithContext(context.Background())
}
func (i *Foo) ToFooOutputWithContext(ctx context.Context) FooOutput {
return pulumi.ToOutputWithContext(ctx, i).(FooOutput)
}
type FooOutput struct{ *pulumi.OutputState }
func (FooOutput) ElementType() reflect.Type {
return reflect.TypeOf((**Foo)(nil)).Elem()
}
func (o FooOutput) ToFooOutput() FooOutput {
return o
}
func (o FooOutput) ToFooOutputWithContext(ctx context.Context) FooOutput {
return o
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*FooInput)(nil)).Elem(), &Foo{})
pulumi.RegisterOutputType(FooOutput{})
pulumi.RegisterOutputType(FooBarResultOutput{})
pulumi.RegisterOutputType(FooGenerateKubeconfigResultOutput{})
}