Skip to content

Commit d5e3203

Browse files
committed
Make functional option functions return a function
1 parent aefbcb0 commit d5e3203

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changes
22

3+
## 2.0.0-beta.4
4+
5+
- `IncludeNetworksWithoutData` and `IncludeAliasedNetworks` now return a
6+
`NetworksOption` rather than being one themselves. This was done to improve
7+
the documentation organization.
8+
39
## 2.0.0-beta.3 - 2025-02-16
410

511
- `Open` will now fall back to loading the database in memory if the

traverse.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,18 @@ type NetworksOption func(*networkOptions)
3232
// IncludeAliasedNetworks is an option for Networks and NetworksWithin
3333
// that makes them iterate over aliases of the IPv4 subtree in an IPv6
3434
// database, e.g., ::ffff:0:0/96, 2001::/32, and 2002::/16.
35-
func IncludeAliasedNetworks(networks *networkOptions) {
36-
networks.includeAliasedNetworks = true
35+
func IncludeAliasedNetworks() NetworksOption {
36+
return func(networks *networkOptions) {
37+
networks.includeAliasedNetworks = true
38+
}
3739
}
3840

3941
// IncludeNetworksWithoutData is an option for Networks and NetworksWithin
4042
// that makes them include networks without any data in the iteration.
41-
func IncludeNetworksWithoutData(networks *networkOptions) {
42-
networks.includeEmptyNetworks = true
43+
func IncludeNetworksWithoutData() NetworksOption {
44+
return func(networks *networkOptions) {
45+
networks.includeEmptyNetworks = true
46+
}
4347
}
4448

4549
// Networks returns an iterator that can be used to traverse the networks in

traverse_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ var tests = []networkTest{
227227
"2002:101:110::/44",
228228
"2002:101:120::/48",
229229
},
230-
Options: []NetworksOption{IncludeAliasedNetworks},
230+
Options: []NetworksOption{IncludeAliasedNetworks()},
231231
},
232232
{
233233
Network: "::/0",
@@ -281,7 +281,7 @@ var tests = []networkTest{
281281
"1.64.0.0/10",
282282
"1.128.0.0/9",
283283
},
284-
Options: []NetworksOption{IncludeNetworksWithoutData},
284+
Options: []NetworksOption{IncludeNetworksWithoutData()},
285285
},
286286
{
287287
Network: "1.1.1.16/28",

0 commit comments

Comments
 (0)