Skip to content

Commit a33c0e0

Browse files
committed
Run gofumpt on code
1 parent 629da96 commit a33c0e0

File tree

7 files changed

+52
-49
lines changed

7 files changed

+52
-49
lines changed

decoder.go

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func (d *decoder) decodeFromType(
157157
}
158158
}
159159

160-
func (d *decoder) unmarshalBool(size uint, offset uint, result reflect.Value) (uint, error) {
160+
func (d *decoder) unmarshalBool(size, offset uint, result reflect.Value) (uint, error) {
161161
if size > 1 {
162162
return 0, newInvalidDatabaseError("the MaxMind DB file's data section contains bad data (bool size of %v)", size)
163163
}
@@ -206,7 +206,7 @@ func (d *decoder) indirect(result reflect.Value) reflect.Value {
206206

207207
var sliceType = reflect.TypeOf([]byte{})
208208

209-
func (d *decoder) unmarshalBytes(size uint, offset uint, result reflect.Value) (uint, error) {
209+
func (d *decoder) unmarshalBytes(size, offset uint, result reflect.Value) (uint, error) {
210210
value, newOffset := d.decodeBytes(size, offset)
211211

212212
switch result.Kind() {
@@ -224,7 +224,7 @@ func (d *decoder) unmarshalBytes(size uint, offset uint, result reflect.Value) (
224224
return newOffset, newUnmarshalTypeError(value, result.Type())
225225
}
226226

227-
func (d *decoder) unmarshalFloat32(size uint, offset uint, result reflect.Value) (uint, error) {
227+
func (d *decoder) unmarshalFloat32(size, offset uint, result reflect.Value) (uint, error) {
228228
if size != 4 {
229229
return 0, newInvalidDatabaseError("the MaxMind DB file's data section contains bad data (float32 size of %v)", size)
230230
}
@@ -243,8 +243,7 @@ func (d *decoder) unmarshalFloat32(size uint, offset uint, result reflect.Value)
243243
return newOffset, newUnmarshalTypeError(value, result.Type())
244244
}
245245

246-
func (d *decoder) unmarshalFloat64(size uint, offset uint, result reflect.Value) (uint, error) {
247-
246+
func (d *decoder) unmarshalFloat64(size, offset uint, result reflect.Value) (uint, error) {
248247
if size != 8 {
249248
return 0, newInvalidDatabaseError("the MaxMind DB file's data section contains bad data (float 64 size of %v)", size)
250249
}
@@ -266,7 +265,7 @@ func (d *decoder) unmarshalFloat64(size uint, offset uint, result reflect.Value)
266265
return newOffset, newUnmarshalTypeError(value, result.Type())
267266
}
268267

269-
func (d *decoder) unmarshalInt32(size uint, offset uint, result reflect.Value) (uint, error) {
268+
func (d *decoder) unmarshalInt32(size, offset uint, result reflect.Value) (uint, error) {
270269
if size > 4 {
271270
return 0, newInvalidDatabaseError("the MaxMind DB file's data section contains bad data (int32 size of %v)", size)
272271
}
@@ -319,7 +318,7 @@ func (d *decoder) unmarshalMap(
319318
}
320319
}
321320

322-
func (d *decoder) unmarshalPointer(size uint, offset uint, result reflect.Value, depth int) (uint, error) {
321+
func (d *decoder) unmarshalPointer(size, offset uint, result reflect.Value, depth int) (uint, error) {
323322
pointer, newOffset, err := d.decodePointer(size, offset)
324323
if err != nil {
325324
return 0, err
@@ -349,7 +348,7 @@ func (d *decoder) unmarshalSlice(
349348
return 0, newUnmarshalTypeError("array", result.Type())
350349
}
351350

352-
func (d *decoder) unmarshalString(size uint, offset uint, result reflect.Value) (uint, error) {
351+
func (d *decoder) unmarshalString(size, offset uint, result reflect.Value) (uint, error) {
353352
value, newOffset := d.decodeString(size, offset)
354353

355354
switch result.Kind() {
@@ -363,10 +362,9 @@ func (d *decoder) unmarshalString(size uint, offset uint, result reflect.Value)
363362
}
364363
}
365364
return newOffset, newUnmarshalTypeError(value, result.Type())
366-
367365
}
368366

369-
func (d *decoder) unmarshalUint(size uint, offset uint, result reflect.Value, uintType uint) (uint, error) {
367+
func (d *decoder) unmarshalUint(size, offset uint, result reflect.Value, uintType uint) (uint, error) {
370368
if size > uintType/8 {
371369
return 0, newInvalidDatabaseError("the MaxMind DB file's data section contains bad data (uint%v size of %v)", uintType, size)
372370
}
@@ -396,7 +394,7 @@ func (d *decoder) unmarshalUint(size uint, offset uint, result reflect.Value, ui
396394

397395
var bigIntType = reflect.TypeOf(big.Int{})
398396

399-
func (d *decoder) unmarshalUint128(size uint, offset uint, result reflect.Value) (uint, error) {
397+
func (d *decoder) unmarshalUint128(size, offset uint, result reflect.Value) (uint, error) {
400398
if size > 16 {
401399
return 0, newInvalidDatabaseError("the MaxMind DB file's data section contains bad data (uint128 size of %v)", size)
402400
}
@@ -417,30 +415,30 @@ func (d *decoder) unmarshalUint128(size uint, offset uint, result reflect.Value)
417415
return newOffset, newUnmarshalTypeError(value, result.Type())
418416
}
419417

420-
func (d *decoder) decodeBool(size uint, offset uint) (bool, uint) {
418+
func (d *decoder) decodeBool(size, offset uint) (bool, uint) {
421419
return size != 0, offset
422420
}
423421

424-
func (d *decoder) decodeBytes(size uint, offset uint) ([]byte, uint) {
422+
func (d *decoder) decodeBytes(size, offset uint) ([]byte, uint) {
425423
newOffset := offset + size
426424
bytes := make([]byte, size)
427425
copy(bytes, d.buffer[offset:newOffset])
428426
return bytes, newOffset
429427
}
430428

431-
func (d *decoder) decodeFloat64(size uint, offset uint) (float64, uint) {
429+
func (d *decoder) decodeFloat64(size, offset uint) (float64, uint) {
432430
newOffset := offset + size
433431
bits := binary.BigEndian.Uint64(d.buffer[offset:newOffset])
434432
return math.Float64frombits(bits), newOffset
435433
}
436434

437-
func (d *decoder) decodeFloat32(size uint, offset uint) (float32, uint) {
435+
func (d *decoder) decodeFloat32(size, offset uint) (float32, uint) {
438436
newOffset := offset + size
439437
bits := binary.BigEndian.Uint32(d.buffer[offset:newOffset])
440438
return math.Float32frombits(bits), newOffset
441439
}
442440

443-
func (d *decoder) decodeInt(size uint, offset uint) (int, uint) {
441+
func (d *decoder) decodeInt(size, offset uint) (int, uint) {
444442
newOffset := offset + size
445443
var val int32
446444
for _, b := range d.buffer[offset:newOffset] {
@@ -540,7 +538,7 @@ func (d *decoder) decodeSlice(
540538
return offset, nil
541539
}
542540

543-
func (d *decoder) decodeString(size uint, offset uint) (string, uint) {
541+
func (d *decoder) decodeString(size, offset uint) (string, uint) {
544542
newOffset := offset + size
545543
return string(d.buffer[offset:newOffset]), newOffset
546544
}
@@ -628,7 +626,7 @@ func cachedFields(result reflect.Value) *fieldsType {
628626
return fields
629627
}
630628

631-
func (d *decoder) decodeUint(size uint, offset uint) (uint64, uint) {
629+
func (d *decoder) decodeUint(size, offset uint) (uint64, uint) {
632630
newOffset := offset + size
633631
bytes := d.buffer[offset:newOffset]
634632

@@ -639,7 +637,7 @@ func (d *decoder) decodeUint(size uint, offset uint) (uint64, uint) {
639637
return val, newOffset
640638
}
641639

642-
func (d *decoder) decodeUint128(size uint, offset uint) (*big.Int, uint) {
640+
func (d *decoder) decodeUint128(size, offset uint) (*big.Int, uint) {
643641
newOffset := offset + size
644642
val := new(big.Int)
645643
val.SetBytes(d.buffer[offset:newOffset])
@@ -685,7 +683,7 @@ func (d *decoder) decodeKey(offset uint) ([]byte, uint, error) {
685683
// This function is used to skip ahead to the next value without decoding
686684
// the one at the offset passed in. The size bits have different meanings for
687685
// different data types
688-
func (d *decoder) nextValueOffset(offset uint, numberToSkip uint) (uint, error) {
686+
func (d *decoder) nextValueOffset(offset, numberToSkip uint) (uint, error) {
689687
if numberToSkip == 0 {
690688
return offset, nil
691689
}

decoder_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,5 +237,4 @@ func TestPointers(t *testing.T) {
237237
t.Errorf("Decode for pointer at %d failed", offset)
238238
}
239239
}
240-
241240
}

example_test.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ func ExampleReader_Networks() {
153153
// 2002:c9f3:c800::/40: Corporate
154154
// 2002:cfb3:3000::/36: Cellular
155155
// 2003::/24: Cable/DSL
156-
157156
}
158157

159158
// This example demonstrates how to iterate over all networks in the
@@ -187,14 +186,13 @@ func ExampleReader_NetworksWithin() {
187186
}
188187

189188
// Output:
190-
//1.0.0.0/24: Dialup
191-
//1.0.1.0/24: Cable/DSL
192-
//1.0.2.0/23: Dialup
193-
//1.0.4.0/22: Dialup
194-
//1.0.8.0/21: Dialup
195-
//1.0.16.0/20: Dialup
196-
//1.0.32.0/19: Dialup
197-
//1.0.64.0/18: Dialup
198-
//1.0.128.0/17: Dialup
199-
189+
// 1.0.0.0/24: Dialup
190+
// 1.0.1.0/24: Cable/DSL
191+
// 1.0.2.0/23: Dialup
192+
// 1.0.4.0/22: Dialup
193+
// 1.0.8.0/21: Dialup
194+
// 1.0.16.0/20: Dialup
195+
// 1.0.32.0/19: Dialup
196+
// 1.0.64.0/18: Dialup
197+
// 1.0.128.0/17: Dialup
200198
}

mmap_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"golang.org/x/sys/unix"
77
)
88

9-
func mmap(fd int, length int) (data []byte, err error) {
9+
func mmap(fd, length int) (data []byte, err error) {
1010
return unix.Mmap(fd, 0, length, unix.PROT_READ, unix.MAP_SHARED)
1111
}
1212

reader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func (r *Reader) lookupPointer(ip net.IP) (uint, int, net.IP, error) {
262262
return 0, prefixLength, ip, newInvalidDatabaseError("invalid node in search tree")
263263
}
264264

265-
func (r *Reader) traverseTree(ip net.IP, node uint, bitCount uint) (uint, int) {
265+
func (r *Reader) traverseTree(ip net.IP, node, bitCount uint) (uint, int) {
266266
nodeCount := r.Metadata.NodeCount
267267

268268
i := uint(0)
@@ -289,7 +289,7 @@ func (r *Reader) retrieveData(pointer uint, result interface{}) error {
289289
}
290290

291291
func (r *Reader) resolveDataPointer(pointer uint) (uintptr, error) {
292-
var resolved = uintptr(pointer - r.Metadata.NodeCount - dataSectionSeparatorSize)
292+
resolved := uintptr(pointer - r.Metadata.NodeCount - dataSectionSeparatorSize)
293293

294294
if resolved >= uintptr(len(r.buffer)) {
295295
return 0, newInvalidDatabaseError("the MaxMind DB file's search tree is corrupt")

reader_test.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,12 @@ func TestReaderBytes(t *testing.T) {
5454
func TestLookupNetwork(t *testing.T) {
5555
bigInt := new(big.Int)
5656
bigInt.SetString("1329227995784915872903807060280344576", 10)
57-
decoderRecord := map[string]interface{}{"array": []interface{}{uint64(1),
58-
uint64(2),
59-
uint64(3)},
57+
decoderRecord := map[string]interface{}{
58+
"array": []interface{}{
59+
uint64(1),
60+
uint64(2),
61+
uint64(3),
62+
},
6063
"boolean": true,
6164
"bytes": []uint8{
6265
0x0,
@@ -72,7 +75,8 @@ func TestLookupNetwork(t *testing.T) {
7275
"arrayX": []interface{}{
7376
uint64(0x7),
7477
uint64(0x8),
75-
uint64(0x9)},
78+
uint64(0x9),
79+
},
7680
"utf8_stringX": "hello",
7781
},
7882
},
@@ -211,7 +215,8 @@ func TestDecodingToInterface(t *testing.T) {
211215
"mapX": map[string]interface{}{
212216
"arrayX": []interface{}{uint64(7), uint64(8), uint64(9)},
213217
"utf8_stringX": "hello",
214-
}},
218+
},
219+
},
215220
record["map"],
216221
)
217222

@@ -257,7 +262,8 @@ func TestDecoder(t *testing.T) {
257262
"mapX": map[string]interface{}{
258263
"arrayX": []interface{}{uint64(7), uint64(8), uint64(9)},
259264
"utf8_stringX": "hello",
260-
}},
265+
},
266+
},
261267
result.Map,
262268
)
263269

@@ -351,7 +357,7 @@ type ValueTypeTestType struct {
351357
Boolean BoolInterface `maxminddb:"boolean"`
352358
}
353359

354-
func TesValueTypeInterface(t *testing.T) {
360+
func TestValueTypeInterface(t *testing.T) {
355361
var result ValueTypeTestType
356362
result.Boolean = Bool(false)
357363

@@ -558,7 +564,7 @@ func TestUsingClosedDatabase(t *testing.T) {
558564
assert.Equal(t, "cannot call Decode on a closed database", err.Error())
559565
}
560566

561-
func checkMetadata(t *testing.T, reader *Reader, ipVersion uint, recordSize uint) {
567+
func checkMetadata(t *testing.T, reader *Reader, ipVersion, recordSize uint) {
562568
metadata := reader.Metadata
563569

564570
assert.Equal(t, uint(2), metadata.BinaryFormatMajorVersion)
@@ -585,7 +591,6 @@ func checkMetadata(t *testing.T, reader *Reader, ipVersion uint, recordSize uint
585591
}
586592

587593
func checkIpv4(t *testing.T, reader *Reader) {
588-
589594
for i := uint(0); i < 6; i++ {
590595
address := fmt.Sprintf("1.1.1.%d", uint(1)<<i)
591596
ip := net.ParseIP(address)
@@ -627,9 +632,10 @@ func checkIpv4(t *testing.T, reader *Reader) {
627632
}
628633

629634
func checkIpv6(t *testing.T, reader *Reader) {
630-
631-
subnets := []string{"::1:ffff:ffff", "::2:0:0",
632-
"::2:0:40", "::2:0:50", "::2:0:58"}
635+
subnets := []string{
636+
"::1:ffff:ffff", "::2:0:0",
637+
"::2:0:40", "::2:0:50", "::2:0:58",
638+
}
633639

634640
for _, address := range subnets {
635641
var result map[string]string

traverse.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ type Networks struct {
1919
err error
2020
}
2121

22-
var allIPv4 = &net.IPNet{IP: make(net.IP, 4), Mask: net.CIDRMask(0, 32)}
23-
var allIPv6 = &net.IPNet{IP: make(net.IP, 16), Mask: net.CIDRMask(0, 128)}
22+
var (
23+
allIPv4 = &net.IPNet{IP: make(net.IP, 4), Mask: net.CIDRMask(0, 32)}
24+
allIPv6 = &net.IPNet{IP: make(net.IP, 16), Mask: net.CIDRMask(0, 128)}
25+
)
2426

2527
// Networks returns an iterator that can be used to traverse all networks in
2628
// the database.

0 commit comments

Comments
 (0)