This repository has been archived by the owner on Dec 30, 2024. It is now read-only.
generated from FrangipaneTeam/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathobject_value.go
137 lines (103 loc) · 3.66 KB
/
object_value.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// -------------------------------------------------------------------- //
// ! DO NOT EDIT. This file is auto-generated from template ! //
// -------------------------------------------------------------------- //
package supertypes
import (
"context"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
)
// Ensure the implementation satisfies the expected interfaces.
var _ basetypes.ObjectValuable = ObjectValue{}
type ObjectValue struct {
basetypes.ObjectValue
}
func (v ObjectValue) Equal(o attr.Value) bool {
other, ok := o.(ObjectValue)
if !ok {
return false
}
return v.ObjectValue.Equal(other.ObjectValue)
}
func (v ObjectValue) Type(_ context.Context) attr.Type {
return ObjectType{}
}
func NewObjectNull(attributeTypes map[string]attr.Type) ObjectValue {
return ObjectValue{
ObjectValue: basetypes.NewObjectNull(attributeTypes),
}
}
func NewObjectUnknown(attributeTypes map[string]attr.Type) ObjectValue {
return ObjectValue{
ObjectValue: basetypes.NewObjectUnknown(attributeTypes),
}
}
// * CustomFunc
func (v *ObjectValue) Get(ctx context.Context, target interface{}, opts basetypes.ObjectAsOptions) diag.Diagnostics {
return v.ObjectValue.As(ctx, target, opts)
}
func (v *ObjectValue) Set(ctx context.Context, structure any) diag.Diagnostics {
var d diag.Diagnostics
v.ObjectValue, d = basetypes.NewObjectValueFrom(ctx, v.AttributeTypes(ctx), structure)
return d
}
func (v *ObjectValue) SetNull(ctx context.Context) {
v.ObjectValue = basetypes.NewObjectNull(v.AttributeTypes(ctx))
}
func (v *ObjectValue) SetUnknown(ctx context.Context) {
v.ObjectValue = basetypes.NewObjectUnknown(v.AttributeTypes(ctx))
}
func (v ObjectValue) IsKnown() bool {
return !v.ObjectValue.IsNull() && !v.ObjectValue.IsUnknown()
}
// ObjectValueOf represents a Terraform Plugin Framework Object value whose corresponding Go type is the structure T.
type ObjectValueOf[T any] struct {
basetypes.ObjectValue
}
var _ basetypes.ObjectValuable = ObjectValueOf[struct{}]{}
func (v ObjectValueOf[T]) Equal(o attr.Value) bool {
other, ok := o.(ObjectValueOf[T])
if !ok {
return false
}
return v.ObjectValue.Equal(other.ObjectValue)
}
func (v ObjectValueOf[T]) Type(ctx context.Context) attr.Type {
return NewObjectTypeOf[T](ctx)
}
func NewObjectValueOfNull[T any](ctx context.Context) ObjectValueOf[T] {
return ObjectValueOf[T]{ObjectValue: basetypes.NewObjectNull(AttributeTypesMust[T](ctx))}
}
func NewObjectValueOfUnknown[T any](ctx context.Context) ObjectValueOf[T] {
return ObjectValueOf[T]{ObjectValue: basetypes.NewObjectUnknown(AttributeTypesMust[T](ctx))}
}
func NewObjectValueOf[T any](ctx context.Context, t *T) ObjectValueOf[T] {
return ObjectValueOf[T]{ObjectValue: MustDiag(basetypes.NewObjectValueFrom(ctx, AttributeTypesMust[T](ctx), t))}
}
func (v ObjectValueOf[T]) Get(ctx context.Context) (*T, diag.Diagnostics) {
var diags diag.Diagnostics
ptr := new(T)
diags.Append(v.ObjectValue.As(ctx, ptr, basetypes.ObjectAsOptions{})...)
if diags.HasError() {
return nil, diags
}
return ptr, diags
}
func (v *ObjectValueOf[T]) Set(ctx context.Context, t *T) (diags diag.Diagnostics) {
v.ObjectValue, diags = basetypes.NewObjectValueFrom(ctx, AttributeTypesMust[T](ctx), t)
return diags
}
// IsKnown returns whether the value is known.
func (v ObjectValueOf[T]) IsKnown() bool {
if !v.IsNull() && !v.IsUnknown() {
return true
}
return false
}
func (v *ObjectValueOf[T]) SetNull(ctx context.Context) {
*v = NewObjectValueOfNull[T](ctx)
}
func (v *ObjectValueOf[T]) SetUnknown(ctx context.Context) {
*v = NewObjectValueOfUnknown[T](ctx)
}