From 42cb12d795b3cba507d07d34084668c938214326 Mon Sep 17 00:00:00 2001 From: aq17 Date: Mon, 5 Dec 2022 13:48:45 -0800 Subject: [PATCH] Add *[TYPE] to [TYPE]ptr methods --- ...pes-to-corresponding-pulumi-ptr-types.yaml | 4 +++ .../templates/types_builtins.go.template | 6 ++++ sdk/go/pulumi/types_builtins.go | 36 +++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 changelog/pending/20221205--sdk--add-methods-to-cast-pointer-types-to-corresponding-pulumi-ptr-types.yaml diff --git a/changelog/pending/20221205--sdk--add-methods-to-cast-pointer-types-to-corresponding-pulumi-ptr-types.yaml b/changelog/pending/20221205--sdk--add-methods-to-cast-pointer-types-to-corresponding-pulumi-ptr-types.yaml new file mode 100644 index 000000000000..98064d91c897 --- /dev/null +++ b/changelog/pending/20221205--sdk--add-methods-to-cast-pointer-types-to-corresponding-pulumi-ptr-types.yaml @@ -0,0 +1,4 @@ +changes: +- type: feat + scope: sdk + description: Add methods to cast pointer types to corresponding Pulumi Ptr types diff --git a/sdk/go/pulumi/generate/templates/types_builtins.go.template b/sdk/go/pulumi/generate/templates/types_builtins.go.template index 0777ad28c864..5ac68f4f2a83 100644 --- a/sdk/go/pulumi/generate/templates/types_builtins.go.template +++ b/sdk/go/pulumi/generate/templates/types_builtins.go.template @@ -47,6 +47,12 @@ type {{.PtrType}} {{.ElemElementType}} func {{.Name}}(v {{.ElemElementType}}) {{.Name}}Input { return ({{.InputType}})(&v) } +func {{.Name}}FromPtr(v *{{.ElemElementType}}) {{.Name}}Input { + if v == nil { + return nil + } + return ({{.InputType}})(v) +} {{end}} {{if .DefineInputMethods}} // ElementType returns the element type of this Input ({{.ElementType}}). diff --git a/sdk/go/pulumi/types_builtins.go b/sdk/go/pulumi/types_builtins.go index f276ce12e3e3..868c49c4ecbd 100644 --- a/sdk/go/pulumi/types_builtins.go +++ b/sdk/go/pulumi/types_builtins.go @@ -1378,6 +1378,12 @@ type boolPtr bool func BoolPtr(v bool) BoolPtrInput { return (*boolPtr)(&v) } +func BoolPtrFromPtr(v *bool) BoolPtrInput { + if v == nil { + return nil + } + return (*boolPtr)(v) +} // ElementType returns the element type of this Input (*bool). func (*boolPtr) ElementType() reflect.Type { @@ -1909,6 +1915,12 @@ type float64Ptr float64 func Float64Ptr(v float64) Float64PtrInput { return (*float64Ptr)(&v) } +func Float64PtrFromPtr(v *float64) Float64PtrInput { + if v == nil { + return nil + } + return (*float64Ptr)(v) +} // ElementType returns the element type of this Input (*float64). func (*float64Ptr) ElementType() reflect.Type { @@ -2455,6 +2467,12 @@ type idPtr ID func IDPtr(v ID) IDPtrInput { return (*idPtr)(&v) } +func IDPtrFromPtr(v *ID) IDPtrInput { + if v == nil { + return nil + } + return (*idPtr)(v) +} // ElementType returns the element type of this Input (*ID). func (*idPtr) ElementType() reflect.Type { @@ -3462,6 +3480,12 @@ type intPtr int func IntPtr(v int) IntPtrInput { return (*intPtr)(&v) } +func IntPtrFromPtr(v *int) IntPtrInput { + if v == nil { + return nil + } + return (*intPtr)(v) +} // ElementType returns the element type of this Input (*int). func (*intPtr) ElementType() reflect.Type { @@ -3993,6 +4017,12 @@ type stringPtr string func StringPtr(v string) StringPtrInput { return (*stringPtr)(&v) } +func StringPtrFromPtr(v *string) StringPtrInput { + if v == nil { + return nil + } + return (*stringPtr)(v) +} // ElementType returns the element type of this Input (*string). func (*stringPtr) ElementType() reflect.Type { @@ -4539,6 +4569,12 @@ type urnPtr URN func URNPtr(v URN) URNPtrInput { return (*urnPtr)(&v) } +func URNPtrFromPtr(v *URN) URNPtrInput { + if v == nil { + return nil + } + return (*urnPtr)(v) +} // ElementType returns the element type of this Input (*URN). func (*urnPtr) ElementType() reflect.Type {