Skip to content

Commit eeae704

Browse files
committed
Minor style changes
1 parent 6111b52 commit eeae704

File tree

10 files changed

+102
-102
lines changed

10 files changed

+102
-102
lines changed

decoder.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@ func (d *decoder) decodeFromType(
151151
result reflect.Value,
152152
depth int,
153153
) (uint, error) {
154-
result = d.indirect(result)
154+
result = indirect(result)
155155

156156
// For these types, size has a special meaning
157157
switch dtype {
158158
case _Bool:
159-
return d.unmarshalBool(size, offset, result)
159+
return unmarshalBool(size, offset, result)
160160
case _Map:
161161
return d.unmarshalMap(size, offset, result, depth)
162162
case _Pointer:
@@ -203,7 +203,7 @@ func (d *decoder) decodeFromTypeToDeserializer(
203203
// For these types, size has a special meaning
204204
switch dtype {
205205
case _Bool:
206-
v, offset := d.decodeBool(size, offset)
206+
v, offset := decodeBool(size, offset)
207207
return offset, dser.Bool(v)
208208
case _Map:
209209
return d.decodeMapToDeserializer(size, offset, dser, depth)
@@ -255,14 +255,14 @@ func (d *decoder) decodeFromTypeToDeserializer(
255255
}
256256
}
257257

258-
func (d *decoder) unmarshalBool(size, offset uint, result reflect.Value) (uint, error) {
258+
func unmarshalBool(size, offset uint, result reflect.Value) (uint, error) {
259259
if size > 1 {
260260
return 0, newInvalidDatabaseError(
261261
"the MaxMind DB file's data section contains bad data (bool size of %v)",
262262
size,
263263
)
264264
}
265-
value, newOffset := d.decodeBool(size, offset)
265+
value, newOffset := decodeBool(size, offset)
266266

267267
switch result.Kind() {
268268
case reflect.Bool:
@@ -281,7 +281,7 @@ func (d *decoder) unmarshalBool(size, offset uint, result reflect.Value) (uint,
281281
// heavily based on encoding/json as my original version had a subtle
282282
// bug. This method should be considered to be licensed under
283283
// https://golang.org/LICENSE
284-
func (d *decoder) indirect(result reflect.Value) reflect.Value {
284+
func indirect(result reflect.Value) reflect.Value {
285285
for {
286286
// Load value from interface, but only if the result will be
287287
// usefully addressable.
@@ -415,7 +415,7 @@ func (d *decoder) unmarshalMap(
415415
result reflect.Value,
416416
depth int,
417417
) (uint, error) {
418-
result = d.indirect(result)
418+
result = indirect(result)
419419
switch result.Kind() {
420420
default:
421421
return 0, newUnmarshalTypeError("map", result.Type())
@@ -425,7 +425,7 @@ func (d *decoder) unmarshalMap(
425425
return d.decodeMap(size, offset, result, depth)
426426
case reflect.Interface:
427427
if result.NumMethod() == 0 {
428-
rv := reflect.ValueOf(make(map[string]interface{}, size))
428+
rv := reflect.ValueOf(make(map[string]any, size))
429429
newOffset, err := d.decodeMap(size, offset, rv, depth)
430430
result.Set(rv)
431431
return newOffset, err
@@ -458,7 +458,7 @@ func (d *decoder) unmarshalSlice(
458458
return d.decodeSlice(size, offset, result, depth)
459459
case reflect.Interface:
460460
if result.NumMethod() == 0 {
461-
a := []interface{}{}
461+
a := []any{}
462462
rv := reflect.ValueOf(&a).Elem()
463463
newOffset, err := d.decodeSlice(size, offset, rv, depth)
464464
result.Set(rv)
@@ -551,7 +551,7 @@ func (d *decoder) unmarshalUint128(size, offset uint, result reflect.Value) (uin
551551
return newOffset, newUnmarshalTypeError(value, result.Type())
552552
}
553553

554-
func (d *decoder) decodeBool(size, offset uint) (bool, uint) {
554+
func decodeBool(size, offset uint) (bool, uint) {
555555
return size != 0, offset
556556
}
557557

decoder_test.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
func TestBool(t *testing.T) {
16-
bools := map[string]interface{}{
16+
bools := map[string]any{
1717
"0007": false,
1818
"0107": true,
1919
}
@@ -22,7 +22,7 @@ func TestBool(t *testing.T) {
2222
}
2323

2424
func TestDouble(t *testing.T) {
25-
doubles := map[string]interface{}{
25+
doubles := map[string]any{
2626
"680000000000000000": 0.0,
2727
"683FE0000000000000": 0.5,
2828
"68400921FB54442EEA": 3.14159265359,
@@ -36,7 +36,7 @@ func TestDouble(t *testing.T) {
3636
}
3737

3838
func TestFloat(t *testing.T) {
39-
floats := map[string]interface{}{
39+
floats := map[string]any{
4040
"040800000000": float32(0.0),
4141
"04083F800000": float32(1.0),
4242
"04083F8CCCCD": float32(1.1),
@@ -51,7 +51,7 @@ func TestFloat(t *testing.T) {
5151
}
5252

5353
func TestInt32(t *testing.T) {
54-
int32s := map[string]interface{}{
54+
int32s := map[string]any{
5555
"0001": 0,
5656
"0401ffffffff": -1,
5757
"0101ff": 255,
@@ -69,33 +69,33 @@ func TestInt32(t *testing.T) {
6969
}
7070

7171
func TestMap(t *testing.T) {
72-
maps := map[string]interface{}{
73-
"e0": map[string]interface{}{},
74-
"e142656e43466f6f": map[string]interface{}{"en": "Foo"},
75-
"e242656e43466f6f427a6843e4baba": map[string]interface{}{"en": "Foo", "zh": "人"},
76-
"e1446e616d65e242656e43466f6f427a6843e4baba": map[string]interface{}{
77-
"name": map[string]interface{}{"en": "Foo", "zh": "人"},
72+
maps := map[string]any{
73+
"e0": map[string]any{},
74+
"e142656e43466f6f": map[string]any{"en": "Foo"},
75+
"e242656e43466f6f427a6843e4baba": map[string]any{"en": "Foo", "zh": "人"},
76+
"e1446e616d65e242656e43466f6f427a6843e4baba": map[string]any{
77+
"name": map[string]any{"en": "Foo", "zh": "人"},
7878
},
79-
"e1496c616e677561676573020442656e427a68": map[string]interface{}{
80-
"languages": []interface{}{"en", "zh"},
79+
"e1496c616e677561676573020442656e427a68": map[string]any{
80+
"languages": []any{"en", "zh"},
8181
},
8282
}
8383
validateDecoding(t, maps)
8484
}
8585

8686
func TestSlice(t *testing.T) {
87-
slice := map[string]interface{}{
88-
"0004": []interface{}{},
89-
"010443466f6f": []interface{}{"Foo"},
90-
"020443466f6f43e4baba": []interface{}{"Foo", "人"},
87+
slice := map[string]any{
88+
"0004": []any{},
89+
"010443466f6f": []any{"Foo"},
90+
"020443466f6f43e4baba": []any{"Foo", "人"},
9191
}
9292
validateDecoding(t, slice)
9393
}
9494

9595
var testStrings = makeTestStrings()
9696

97-
func makeTestStrings() map[string]interface{} {
98-
str := map[string]interface{}{
97+
func makeTestStrings() map[string]any {
98+
str := map[string]any{
9999
"40": "",
100100
"4131": "1",
101101
"43E4BABA": "人",
@@ -118,7 +118,7 @@ func TestString(t *testing.T) {
118118
}
119119

120120
func TestByte(t *testing.T) {
121-
b := make(map[string]interface{})
121+
b := make(map[string]any)
122122
for key, val := range testStrings {
123123
oldCtrl, err := hex.DecodeString(key[0:2])
124124
require.NoError(t, err)
@@ -131,7 +131,7 @@ func TestByte(t *testing.T) {
131131
}
132132

133133
func TestUint16(t *testing.T) {
134-
uint16s := map[string]interface{}{
134+
uint16s := map[string]any{
135135
"a0": uint64(0),
136136
"a1ff": uint64(255),
137137
"a201f4": uint64(500),
@@ -142,7 +142,7 @@ func TestUint16(t *testing.T) {
142142
}
143143

144144
func TestUint32(t *testing.T) {
145-
uint32s := map[string]interface{}{
145+
uint32s := map[string]any{
146146
"c0": uint64(0),
147147
"c1ff": uint64(255),
148148
"c201f4": uint64(500),
@@ -158,7 +158,7 @@ func TestUint64(t *testing.T) {
158158
ctrlByte := "02"
159159
bits := uint64(64)
160160

161-
uints := map[string]interface{}{
161+
uints := map[string]any{
162162
"00" + ctrlByte: uint64(0),
163163
"02" + ctrlByte + "01f4": uint64(500),
164164
"02" + ctrlByte + "2a78": uint64(10872),
@@ -178,7 +178,7 @@ func TestUint128(t *testing.T) {
178178
ctrlByte := "03"
179179
bits := uint(128)
180180

181-
uints := map[string]interface{}{
181+
uints := map[string]any{
182182
"00" + ctrlByte: big.NewInt(0),
183183
"02" + ctrlByte + "01f4": big.NewInt(500),
184184
"02" + ctrlByte + "2a78": big.NewInt(10872),
@@ -204,13 +204,13 @@ func powBigInt(bi *big.Int, pow uint) *big.Int {
204204
return newInt
205205
}
206206

207-
func validateDecoding(t *testing.T, tests map[string]interface{}) {
207+
func validateDecoding(t *testing.T, tests map[string]any) {
208208
for inputStr, expected := range tests {
209209
inputBytes, err := hex.DecodeString(inputStr)
210210
require.NoError(t, err)
211211
d := decoder{inputBytes}
212212

213-
var result interface{}
213+
var result any
214214
_, err = d.decode(0, reflect.ValueOf(&result), 0)
215215
assert.NoError(t, err)
216216

deserializer_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,26 @@ func TestDecodingToDeserializer(t *testing.T) {
2020
}
2121

2222
type stackValue struct {
23-
value interface{}
23+
value any
2424
curNum int
2525
}
2626

2727
type testDeserializer struct {
2828
stack []*stackValue
29-
rv interface{}
29+
rv any
3030
key *string
3131
}
3232

33-
func (d *testDeserializer) ShouldSkip(_ uintptr) (bool, error) {
33+
func (*testDeserializer) ShouldSkip(_ uintptr) (bool, error) {
3434
return false, nil
3535
}
3636

3737
func (d *testDeserializer) StartSlice(size uint) error {
38-
return d.add(make([]interface{}, size))
38+
return d.add(make([]any, size))
3939
}
4040

4141
func (d *testDeserializer) StartMap(_ uint) error {
42-
return d.add(map[string]interface{}{})
42+
return d.add(map[string]any{})
4343
}
4444

4545
//nolint:unparam // This is to meet the requirements of the interface.
@@ -88,13 +88,13 @@ func (d *testDeserializer) Float32(v float32) error {
8888
return d.add(v)
8989
}
9090

91-
func (d *testDeserializer) add(v interface{}) error {
91+
func (d *testDeserializer) add(v any) error {
9292
if len(d.stack) == 0 {
9393
d.rv = v
9494
} else {
9595
top := d.stack[len(d.stack)-1]
9696
switch parent := top.value.(type) {
97-
case map[string]interface{}:
97+
case map[string]any:
9898
if d.key == nil {
9999
key := v.(string)
100100
d.key = &key
@@ -103,15 +103,15 @@ func (d *testDeserializer) add(v interface{}) error {
103103
d.key = nil
104104
}
105105

106-
case []interface{}:
106+
case []any:
107107
parent[top.curNum] = v
108108
top.curNum++
109109
default:
110110
}
111111
}
112112

113113
switch v := v.(type) {
114-
case map[string]interface{}, []interface{}:
114+
case map[string]any, []any:
115115
d.stack = append(d.stack, &stackValue{value: v})
116116
default:
117117
}

errors.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func newOffsetError() InvalidDatabaseError {
1515
return InvalidDatabaseError{"unexpected end of database"}
1616
}
1717

18-
func newInvalidDatabaseError(format string, args ...interface{}) InvalidDatabaseError {
18+
func newInvalidDatabaseError(format string, args ...any) InvalidDatabaseError {
1919
return InvalidDatabaseError{fmt.Sprintf(format, args...)}
2020
}
2121

@@ -30,7 +30,7 @@ type UnmarshalTypeError struct {
3030
Value string
3131
}
3232

33-
func newUnmarshalTypeError(value interface{}, rType reflect.Type) UnmarshalTypeError {
33+
func newUnmarshalTypeError(value any, rType reflect.Type) UnmarshalTypeError {
3434
return UnmarshalTypeError{
3535
Value: fmt.Sprintf("%v", value),
3636
Type: rType,

example_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func ExampleReader_Lookup_struct() {
3333
// GB
3434
}
3535

36-
// This example demonstrates how to decode to an interface{}.
36+
// This example demonstrates how to decode to an any.
3737
func ExampleReader_Lookup_interface() {
3838
db, err := maxminddb.Open("test-data/test-data/GeoIP2-City-Test.mmdb")
3939
if err != nil {
@@ -43,7 +43,7 @@ func ExampleReader_Lookup_interface() {
4343

4444
ip := net.ParseIP("81.2.69.142")
4545

46-
var record interface{}
46+
var record any
4747
err = db.Lookup(ip, &record)
4848
if err != nil {
4949
log.Panic(err)

reader.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (r *Reader) setIPv4Start() {
130130
// because of type differences, an UnmarshalTypeError is returned. If the
131131
// database is invalid or otherwise cannot be read, an InvalidDatabaseError
132132
// is returned.
133-
func (r *Reader) Lookup(ip net.IP, result interface{}) error {
133+
func (r *Reader) Lookup(ip net.IP, result any) error {
134134
if r.buffer == nil {
135135
return errors.New("cannot call Lookup on a closed database")
136136
}
@@ -152,7 +152,7 @@ func (r *Reader) Lookup(ip net.IP, result interface{}) error {
152152
// cannot be read, an InvalidDatabaseError is returned.
153153
func (r *Reader) LookupNetwork(
154154
ip net.IP,
155-
result interface{},
155+
result any,
156156
) (network *net.IPNet, ok bool, err error) {
157157
if r.buffer == nil {
158158
return nil, false, errors.New("cannot call Lookup on a closed database")
@@ -204,7 +204,7 @@ func (r *Reader) cidr(ip net.IP, prefixLength int) *net.IPNet {
204204
// Decode the record at |offset| into |result|. The result value pointed to
205205
// must be a data value that corresponds to a record in the database. This may
206206
// include a struct representation of the data, a map capable of holding the
207-
// data or an empty interface{} value.
207+
// data or an empty any value.
208208
//
209209
// If result is a pointer to a struct, the struct need not include a field
210210
// for every value that may be in the database. If a field is not present in
@@ -217,14 +217,14 @@ func (r *Reader) cidr(ip net.IP, prefixLength int) *net.IPNet {
217217
// the City database, all records of the same country will reference a
218218
// single representative record for that country. This uintptr behavior allows
219219
// clients to leverage this normalization in their own sub-record caching.
220-
func (r *Reader) Decode(offset uintptr, result interface{}) error {
220+
func (r *Reader) Decode(offset uintptr, result any) error {
221221
if r.buffer == nil {
222222
return errors.New("cannot call Decode on a closed database")
223223
}
224224
return r.decode(offset, result)
225225
}
226226

227-
func (r *Reader) decode(offset uintptr, result interface{}) error {
227+
func (r *Reader) decode(offset uintptr, result any) error {
228228
rv := reflect.ValueOf(result)
229229
if rv.Kind() != reflect.Ptr || rv.IsNil() {
230230
return errors.New("result param must be a pointer")
@@ -292,7 +292,7 @@ func (r *Reader) traverseTree(ip net.IP, node, bitCount uint) (uint, int) {
292292
return node, int(i)
293293
}
294294

295-
func (r *Reader) retrieveData(pointer uint, result interface{}) error {
295+
func (r *Reader) retrieveData(pointer uint, result any) error {
296296
offset, err := r.resolveDataPointer(pointer)
297297
if err != nil {
298298
return err

0 commit comments

Comments
 (0)