Skip to content

Commit

Permalink
Rename Network to Prefix
Browse files Browse the repository at this point in the history
To more closely match net/netip. Also, it may reduce confusion with
Networks and NetworksWithin, which refer to more than just the network.
  • Loading branch information
oschwald committed Aug 18, 2024
1 parent 791db99 commit cb27d1e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func ExampleReader_Networks() {
if err != nil {
log.Panic(err)
}
fmt.Printf("%s: %s\n", result.Network(), record.Domain)
fmt.Printf("%s: %s\n", result.Prefix(), record.Domain)
}
// Output:
// 1.0.0.0/24: Cable/DSL
Expand Down Expand Up @@ -123,7 +123,7 @@ func ExampleReader_NetworksWithin() {
if err != nil {
log.Panic(err)
}
fmt.Printf("%s: %s\n", result.Network(), record.Domain)
fmt.Printf("%s: %s\n", result.Prefix(), record.Domain)
}

// Output:
Expand Down
4 changes: 2 additions & 2 deletions reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func TestLookupNetwork(t *testing.T) {
result := reader.Lookup(test.IP)
require.NoError(t, result.Err())
assert.Equal(t, test.ExpectedFound, result.Found())
assert.Equal(t, test.ExpectedNetwork, result.Network().String())
assert.Equal(t, test.ExpectedNetwork, result.Prefix().String())

require.NoError(t, result.Decode(&record))
assert.Equal(t, test.ExpectedRecord, record)
Expand Down Expand Up @@ -841,7 +841,7 @@ func BenchmarkLookupNetwork(b *testing.B) {
if err := res.Err(); err != nil {
b.Error(err)
}
if !res.Network().IsValid() {
if !res.Prefix().IsValid() {
b.Fatalf("invalid network for %s", ip)
}
}
Expand Down
4 changes: 2 additions & 2 deletions result.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ func (r Result) Offset() uintptr {
return uintptr(r.offset)
}

// Network returns the netip.Prefix representing the network associated with
// Prefix returns the netip.Prefix representing the network associated with
// the data record in the database.
func (r Result) Network() netip.Prefix {
func (r Result) Prefix() netip.Prefix {
ip := r.ip
prefixLen := int(r.prefixLen)

Expand Down
2 changes: 1 addition & 1 deletion traverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (r *Reader) NetworksWithin(prefix netip.Prefix, options ...NetworksOption)
prefixLen: uint8(node.bit),
}
res.err = newInvalidDatabaseError(
"invalid search tree at %s", res.Network())
"invalid search tree at %s", res.Prefix())

yield(res)

Expand Down
6 changes: 3 additions & 3 deletions traverse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestNetworks(t *testing.T) {
err := result.Decode(&record)
require.NoError(t, err)

network := result.Network()
network := result.Prefix()
assert.Equal(t, record.IP, network.Addr().String(),
"expected %s got %s", record.IP, network.Addr().String(),
)
Expand Down Expand Up @@ -294,7 +294,7 @@ func TestNetworksWithin(t *testing.T) {
}{}
err := result.Decode(&record)
require.NoError(t, err)
innerIPs = append(innerIPs, result.Network().String())
innerIPs = append(innerIPs, result.Prefix().String())
}

assert.Equal(t, v.Expected, innerIPs)
Expand Down Expand Up @@ -333,7 +333,7 @@ func TestGeoIPNetworksWithin(t *testing.T) {
}{}
err := result.Decode(&record)
require.NoError(t, err)
innerIPs = append(innerIPs, result.Network().String())
innerIPs = append(innerIPs, result.Prefix().String())
}

assert.Equal(t, v.Expected, innerIPs)
Expand Down

0 comments on commit cb27d1e

Please sign in to comment.