Skip to content

Commit cb27d1e

Browse files
committed
Rename Network to Prefix
To more closely match net/netip. Also, it may reduce confusion with Networks and NetworksWithin, which refer to more than just the network.
1 parent 791db99 commit cb27d1e

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

example_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func ExampleReader_Networks() {
7272
if err != nil {
7373
log.Panic(err)
7474
}
75-
fmt.Printf("%s: %s\n", result.Network(), record.Domain)
75+
fmt.Printf("%s: %s\n", result.Prefix(), record.Domain)
7676
}
7777
// Output:
7878
// 1.0.0.0/24: Cable/DSL
@@ -123,7 +123,7 @@ func ExampleReader_NetworksWithin() {
123123
if err != nil {
124124
log.Panic(err)
125125
}
126-
fmt.Printf("%s: %s\n", result.Network(), record.Domain)
126+
fmt.Printf("%s: %s\n", result.Prefix(), record.Domain)
127127
}
128128

129129
// Output:

reader_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func TestLookupNetwork(t *testing.T) {
201201
result := reader.Lookup(test.IP)
202202
require.NoError(t, result.Err())
203203
assert.Equal(t, test.ExpectedFound, result.Found())
204-
assert.Equal(t, test.ExpectedNetwork, result.Network().String())
204+
assert.Equal(t, test.ExpectedNetwork, result.Prefix().String())
205205

206206
require.NoError(t, result.Decode(&record))
207207
assert.Equal(t, test.ExpectedRecord, record)
@@ -841,7 +841,7 @@ func BenchmarkLookupNetwork(b *testing.B) {
841841
if err := res.Err(); err != nil {
842842
b.Error(err)
843843
}
844-
if !res.Network().IsValid() {
844+
if !res.Prefix().IsValid() {
845845
b.Fatalf("invalid network for %s", ip)
846846
}
847847
}

result.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ func (r Result) Offset() uintptr {
118118
return uintptr(r.offset)
119119
}
120120

121-
// Network returns the netip.Prefix representing the network associated with
121+
// Prefix returns the netip.Prefix representing the network associated with
122122
// the data record in the database.
123-
func (r Result) Network() netip.Prefix {
123+
func (r Result) Prefix() netip.Prefix {
124124
ip := r.ip
125125
prefixLen := int(r.prefixLen)
126126

traverse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func (r *Reader) NetworksWithin(prefix netip.Prefix, options ...NetworksOption)
146146
prefixLen: uint8(node.bit),
147147
}
148148
res.err = newInvalidDatabaseError(
149-
"invalid search tree at %s", res.Network())
149+
"invalid search tree at %s", res.Prefix())
150150

151151
yield(res)
152152

traverse_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestNetworks(t *testing.T) {
2727
err := result.Decode(&record)
2828
require.NoError(t, err)
2929

30-
network := result.Network()
30+
network := result.Prefix()
3131
assert.Equal(t, record.IP, network.Addr().String(),
3232
"expected %s got %s", record.IP, network.Addr().String(),
3333
)
@@ -294,7 +294,7 @@ func TestNetworksWithin(t *testing.T) {
294294
}{}
295295
err := result.Decode(&record)
296296
require.NoError(t, err)
297-
innerIPs = append(innerIPs, result.Network().String())
297+
innerIPs = append(innerIPs, result.Prefix().String())
298298
}
299299

300300
assert.Equal(t, v.Expected, innerIPs)
@@ -333,7 +333,7 @@ func TestGeoIPNetworksWithin(t *testing.T) {
333333
}{}
334334
err := result.Decode(&record)
335335
require.NoError(t, err)
336-
innerIPs = append(innerIPs, result.Network().String())
336+
innerIPs = append(innerIPs, result.Prefix().String())
337337
}
338338

339339
assert.Equal(t, v.Expected, innerIPs)

0 commit comments

Comments
 (0)