Skip to content

Commit a7e4934

Browse files
committed
Rename interface functions to use 'AsType()' convention
1 parent 80fefcd commit a7e4934

File tree

2 files changed

+50
-50
lines changed

2 files changed

+50
-50
lines changed

patchers/value/value.go

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
// }
1414
//
1515
// // Provides type checking at compile time
16-
// func (v *customInt) IntValue() int {
16+
// func (v *customInt) AsInt() int {
1717
// return v.Int
1818
// }
1919
//
2020
// // Lets us return nil if we need to
21-
// func (v *customInt) AnyValue() any {
21+
// func (v *customInt) AsAny() any {
2222
// return v.Int
2323
// }
2424
//
@@ -68,79 +68,79 @@ var ValueGetter = func() expr.Option {
6868
// A custom type may implement both AnyValuer and a type specific interface to enable both
6969
// compile time checking and the ability to return a `nil` value.
7070
type AnyValuer interface {
71-
AnyValue() any
71+
AsAny() any
7272
}
7373

7474
type IntValuer interface {
75-
IntValue() int
75+
AsInt() int
7676
}
7777

7878
type BoolValuer interface {
79-
BoolValue() bool
79+
AsBool() bool
8080
}
8181

8282
type Int8Valuer interface {
83-
Int8Value() int8
83+
AsInt8() int8
8484
}
8585

8686
type Int16Valuer interface {
87-
Int16Value() int16
87+
AsInt16() int16
8888
}
8989

9090
type Int32Valuer interface {
91-
Int32Value() int32
91+
AsInt32() int32
9292
}
9393

9494
type Int64Valuer interface {
95-
Int64Value() int64
95+
AsInt64() int64
9696
}
9797

9898
type UintValuer interface {
99-
UintValue() uint
99+
AsUint() uint
100100
}
101101

102102
type Uint8Valuer interface {
103-
Uint8Value() uint8
103+
AsUint8() uint8
104104
}
105105

106106
type Uint16Valuer interface {
107-
Uint16Value() uint16
107+
AsUint16() uint16
108108
}
109109

110110
type Uint32Valuer interface {
111-
Uint32Value() uint32
111+
AsUint32() uint32
112112
}
113113

114114
type Uint64Valuer interface {
115-
Uint64Value() uint64
115+
AsUint64() uint64
116116
}
117117

118118
type Float32Valuer interface {
119-
Float32Value() float32
119+
AsFloat32() float32
120120
}
121121

122122
type Float64Valuer interface {
123-
Float64Value() float64
123+
AsFloat64() float64
124124
}
125125

126126
type StringValuer interface {
127-
StringValue() string
127+
AsString() string
128128
}
129129

130130
type TimeValuer interface {
131-
TimeValue() time.Time
131+
AsTime() time.Time
132132
}
133133

134134
type DurationValuer interface {
135-
DurationValue() time.Duration
135+
AsDuration() time.Duration
136136
}
137137

138138
type ArrayValuer interface {
139-
ArrayValue() []any
139+
AsArray() []any
140140
}
141141

142142
type MapValuer interface {
143-
MapValue() map[string]any
143+
AsMap() map[string]any
144144
}
145145

146146
var supportedInterfaces = []reflect.Type{
@@ -194,43 +194,43 @@ func (patcher) ApplyOptions(c *conf.Config) {
194194
func getValue(params ...any) (any, error) {
195195
switch v := params[0].(type) {
196196
case AnyValuer:
197-
return v.AnyValue(), nil
197+
return v.AsAny(), nil
198198
case BoolValuer:
199-
return v.BoolValue(), nil
199+
return v.AsBool(), nil
200200
case IntValuer:
201-
return v.IntValue(), nil
201+
return v.AsInt(), nil
202202
case Int8Valuer:
203-
return v.Int8Value(), nil
203+
return v.AsInt8(), nil
204204
case Int16Valuer:
205-
return v.Int16Value(), nil
205+
return v.AsInt16(), nil
206206
case Int32Valuer:
207-
return v.Int32Value(), nil
207+
return v.AsInt32(), nil
208208
case Int64Valuer:
209-
return v.Int64Value(), nil
209+
return v.AsInt64(), nil
210210
case UintValuer:
211-
return v.UintValue(), nil
211+
return v.AsUint(), nil
212212
case Uint8Valuer:
213-
return v.Uint8Value(), nil
213+
return v.AsUint8(), nil
214214
case Uint16Valuer:
215-
return v.Uint16Value(), nil
215+
return v.AsUint16(), nil
216216
case Uint32Valuer:
217-
return v.Uint32Value(), nil
217+
return v.AsUint32(), nil
218218
case Uint64Valuer:
219-
return v.Uint64Value(), nil
219+
return v.AsUint64(), nil
220220
case Float32Valuer:
221-
return v.Float32Value(), nil
221+
return v.AsFloat32(), nil
222222
case Float64Valuer:
223-
return v.Float64Value(), nil
223+
return v.AsFloat64(), nil
224224
case StringValuer:
225-
return v.StringValue(), nil
225+
return v.AsString(), nil
226226
case TimeValuer:
227-
return v.TimeValue(), nil
227+
return v.AsTime(), nil
228228
case DurationValuer:
229-
return v.DurationValue(), nil
229+
return v.AsDuration(), nil
230230
case ArrayValuer:
231-
return v.ArrayValue(), nil
231+
return v.AsArray(), nil
232232
case MapValuer:
233-
return v.MapValue(), nil
233+
return v.AsMap(), nil
234234
}
235235

236236
return params[0], nil

patchers/value/value_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,71 +13,71 @@ type customInt struct {
1313
Int int
1414
}
1515

16-
func (v *customInt) IntValue() int {
16+
func (v *customInt) AsInt() int {
1717
return v.Int
1818
}
1919

20-
func (v *customInt) AnyValue() any {
20+
func (v *customInt) AsAny() any {
2121
return v.Int
2222
}
2323

2424
type customTypedInt struct {
2525
Int int
2626
}
2727

28-
func (v *customTypedInt) IntValue() int {
28+
func (v *customTypedInt) AsInt() int {
2929
return v.Int
3030
}
3131

3232
type customUntypedInt struct {
3333
Int int
3434
}
3535

36-
func (v *customUntypedInt) AnyValue() any {
36+
func (v *customUntypedInt) AsAny() any {
3737
return v.Int
3838
}
3939

4040
type customString struct {
4141
String string
4242
}
4343

44-
func (v *customString) StringValue() string {
44+
func (v *customString) AsString() string {
4545
return v.String
4646
}
4747

48-
func (v *customString) AnyValue() any {
48+
func (v *customString) AsAny() any {
4949
return v.String
5050
}
5151

5252
type customTypedString struct {
5353
String string
5454
}
5555

56-
func (v *customTypedString) StringValue() string {
56+
func (v *customTypedString) AsString() string {
5757
return v.String
5858
}
5959

6060
type customUntypedString struct {
6161
String string
6262
}
6363

64-
func (v *customUntypedString) AnyValue() any {
64+
func (v *customUntypedString) AsAny() any {
6565
return v.String
6666
}
6767

6868
type customTypedArray struct {
6969
Array []any
7070
}
7171

72-
func (v *customTypedArray) ArrayValue() []any {
72+
func (v *customTypedArray) AsArray() []any {
7373
return v.Array
7474
}
7575

7676
type customTypedMap struct {
7777
Map map[string]any
7878
}
7979

80-
func (v *customTypedMap) MapValue() map[string]any {
80+
func (v *customTypedMap) AsMap() map[string]any {
8181
return v.Map
8282
}
8383

0 commit comments

Comments
 (0)