Skip to content

Commit 62b2953

Browse files
remove redundant cty shim
1 parent fd00d4d commit 62b2953

File tree

2 files changed

+44
-227
lines changed

2 files changed

+44
-227
lines changed

pkg/valueshim/cty.go

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,97 +19,96 @@ import (
1919
"fmt"
2020
"math/big"
2121

22-
"github.com/zclconf/go-cty/cty"
23-
ctyjson "github.com/zclconf/go-cty/cty/json"
22+
"github.com/hashicorp/go-cty/cty"
23+
ctyjson "github.com/hashicorp/go-cty/cty/json"
2424
)
2525

2626
// Wrap a cty.Value as Value.
27-
func FromCtyValue(v cty.Value) Value {
28-
return ctyValueShim(v)
27+
func FromHCtyValue(v cty.Value) Value {
28+
return hctyValueShim(v)
2929
}
3030

3131
// Wrap a cty.Type as Type.
32-
func FromCtyType(v cty.Type) Type {
33-
return ctyTypeShim(v)
32+
func FromHCtyType(v cty.Type) Type {
33+
return hctyTypeShim(v)
3434
}
3535

36-
type ctyValueShim cty.Value
36+
type hctyValueShim cty.Value
3737

38-
var _ Value = (*ctyValueShim)(nil)
38+
var _ Value = (*hctyValueShim)(nil)
3939

40-
func (v ctyValueShim) val() cty.Value {
40+
func (v hctyValueShim) val() cty.Value {
4141
return cty.Value(v)
4242
}
4343

44-
func (v ctyValueShim) IsNull() bool {
44+
func (v hctyValueShim) IsNull() bool {
4545
return v.val().IsNull()
4646
}
4747

48-
func (v ctyValueShim) GoString() string {
48+
func (v hctyValueShim) GoString() string {
4949
return v.val().GoString()
5050
}
5151

52-
func (v ctyValueShim) Type() Type {
53-
return FromCtyType(v.val().Type())
52+
func (v hctyValueShim) Type() Type {
53+
return FromHCtyType(v.val().Type())
5454
}
5555

56-
func (v ctyValueShim) StringValue() string {
56+
func (v hctyValueShim) StringValue() string {
5757
return v.val().AsString()
5858
}
5959

60-
func (v ctyValueShim) BoolValue() bool {
60+
func (v hctyValueShim) BoolValue() bool {
6161
return v.val().True()
6262
}
6363

64-
func (v ctyValueShim) NumberValue() float64 {
65-
bf := v.BigFloatValue()
66-
f, _ := bf.Float64()
64+
func (v hctyValueShim) NumberValue() float64 {
65+
f, _ := v.val().AsBigFloat().Float64()
6766
return f
6867
}
6968

70-
func (v ctyValueShim) BigFloatValue() *big.Float {
69+
func (v hctyValueShim) BigFloatValue() *big.Float {
7170
return v.val().AsBigFloat()
7271
}
7372

74-
func (v ctyValueShim) AsValueSlice() []Value {
73+
func (v hctyValueShim) AsValueSlice() []Value {
7574
s := v.val().AsValueSlice()
7675
res := make([]Value, len(s))
7776
for i, v := range s {
78-
res[i] = ctyValueShim(v)
77+
res[i] = hctyValueShim(v)
7978
}
8079
return res
8180
}
8281

83-
func (v ctyValueShim) AsValueMap() map[string]Value {
82+
func (v hctyValueShim) AsValueMap() map[string]Value {
8483
m := v.val().AsValueMap()
8584
res := make(map[string]Value, len(m))
8685

8786
for k, v := range m {
88-
res[k] = ctyValueShim(v)
87+
res[k] = hctyValueShim(v)
8988
}
9089
return res
9190
}
9291

93-
func (v ctyValueShim) Remove(key string) Value {
92+
func (v hctyValueShim) Remove(key string) Value {
9493
switch {
9594
case v.val().Type().IsObjectType():
9695
m := v.val().AsValueMap()
9796
delete(m, key)
9897
if len(m) == 0 {
99-
return ctyValueShim(cty.EmptyObjectVal)
98+
return hctyValueShim(cty.EmptyObjectVal)
10099
}
101-
return ctyValueShim(cty.ObjectVal(m))
100+
return hctyValueShim(cty.ObjectVal(m))
102101
default:
103102
return v
104103
}
105104
}
106105

107-
func (v ctyValueShim) Marshal(schemaType Type) (json.RawMessage, error) {
106+
func (v hctyValueShim) Marshal(schemaType Type) (json.RawMessage, error) {
108107
vv := v.val()
109-
tt, ok := schemaType.(ctyTypeShim)
108+
tt, ok := schemaType.(hctyTypeShim)
110109
if !ok {
111110
return nil, fmt.Errorf("Cannot marshal to RawState: "+
112-
"expected schemaType to be of type ctyTypeShim, got %#T",
111+
"expected schemaType to be of type hctyTypeShim, got %#T",
113112
schemaType)
114113
}
115114
raw, err := ctyjson.Marshal(vv, tt.ty())
@@ -119,65 +118,65 @@ func (v ctyValueShim) Marshal(schemaType Type) (json.RawMessage, error) {
119118
return json.RawMessage(raw), nil
120119
}
121120

122-
type ctyTypeShim cty.Type
121+
type hctyTypeShim cty.Type
123122

124-
var _ Type = ctyTypeShim{}
123+
var _ Type = hctyTypeShim{}
125124

126-
func (t ctyTypeShim) ty() cty.Type {
125+
func (t hctyTypeShim) ty() cty.Type {
127126
return cty.Type(t)
128127
}
129128

130-
func (t ctyTypeShim) IsNumberType() bool {
129+
func (t hctyTypeShim) IsNumberType() bool {
131130
return t.ty().Equals(cty.Number)
132131
}
133132

134-
func (t ctyTypeShim) IsBooleanType() bool {
133+
func (t hctyTypeShim) IsBooleanType() bool {
135134
return t.ty().Equals(cty.Bool)
136135
}
137136

138-
func (t ctyTypeShim) IsStringType() bool {
137+
func (t hctyTypeShim) IsStringType() bool {
139138
return t.ty().Equals(cty.String)
140139
}
141140

142-
func (t ctyTypeShim) IsListType() bool {
141+
func (t hctyTypeShim) IsListType() bool {
143142
return t.ty().IsListType()
144143
}
145144

146-
func (t ctyTypeShim) IsMapType() bool {
145+
func (t hctyTypeShim) IsMapType() bool {
147146
return t.ty().IsMapType()
148147
}
149148

150-
func (t ctyTypeShim) IsSetType() bool {
149+
func (t hctyTypeShim) IsSetType() bool {
151150
return t.ty().IsSetType()
152151
}
153152

154-
func (t ctyTypeShim) IsObjectType() bool {
153+
func (t hctyTypeShim) IsObjectType() bool {
155154
return t.ty().IsObjectType()
156155
}
157156

158-
func (t ctyTypeShim) IsDynamicType() bool {
157+
func (t hctyTypeShim) IsDynamicType() bool {
159158
return t.ty().Equals(cty.DynamicPseudoType)
160159
}
161160

162-
func (t ctyTypeShim) AttributeType(name string) (Type, bool) {
161+
func (t hctyTypeShim) AttributeType(name string) (Type, bool) {
163162
tt := t.ty()
164163
if !tt.IsObjectType() {
165164
return nil, false
166165
}
167166
if !tt.HasAttribute(name) {
168167
return nil, false
169168
}
170-
return FromCtyType(tt.AttributeType(name)), true
169+
return FromHCtyType(tt.AttributeType(name)), true
171170
}
172171

173-
func (t ctyTypeShim) ElementType() (Type, bool) {
172+
func (t hctyTypeShim) ElementType() (Type, bool) {
174173
tt := t.ty()
175174
if !tt.IsCollectionType() {
176175
return nil, false
177176
}
178-
return FromCtyType(tt.ElementType()), true
177+
return FromHCtyType(tt.ElementType()), true
179178
}
180179

181-
func (t ctyTypeShim) GoString() string {
180+
func (t hctyTypeShim) GoString() string {
182181
return t.ty().GoString()
183182
}

pkg/valueshim/hcty.go

Lines changed: 0 additions & 182 deletions
This file was deleted.

0 commit comments

Comments
 (0)