Skip to content

Commit 7a8cd48

Browse files
committed
Do not have a public Go API
1 parent 30737a3 commit 7a8cd48

File tree

4 files changed

+22
-25
lines changed

4 files changed

+22
-25
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
`network`, and `record`. This allows for efficient streaming of large
1313
lookups, makes the key naming more consistent, and reduces the depth of
1414
the data structure.
15-
* Upgrade to `github.com/oschwald/maxminddb-golang/v2`. This is a breaking
16-
API change, but should not affect the use of the program.
1715
* You may now use a glob for the `-db` argument. If there are multiple
1816
matches, it will be treated as if multiple `-db` arguments were provided.
1917
Note that you must quote the parameter when using globs to prevent the
2018
shell's globbing from interfering. See the [pattern syntax](https://pkg.go.dev/path#Match)
19+
* This repo no longer provides a public Go API. It is only intended to be
20+
used as a CLI program.
2121

2222
## 0.2.0 (2024-01-10)
2323

cmd/mmdbinspect/main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"strings"
1212

1313
"github.com/goccy/go-yaml"
14-
15-
"github.com/maxmind/mmdbinspect/v2/pkg/mmdbinspect"
1614
)
1715

1816
type arrayFlags []string
@@ -67,7 +65,7 @@ func main() {
6765
encoder = yaml.NewEncoder(w)
6866
}
6967

70-
iterator := mmdbinspect.Records(network, mmdb, *includeAliasedNetworks)
68+
iterator := records(network, mmdb, *includeAliasedNetworks)
7169

7270
for r, err := range iterator {
7371
if err != nil {
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// Package mmdbinspect peeks at the contents of .mmdb files
2-
package mmdbinspect
1+
package main
32

43
import (
54
"errors"
@@ -14,21 +13,21 @@ import (
1413
"github.com/oschwald/maxminddb-golang/v2"
1514
)
1615

17-
// Record holds the records for a lookup in a database.
18-
type Record struct {
16+
// record holds the records for a lookup in a database.
17+
type record struct {
1918
DatabasePath string `json:"database_path"`
2019
RequestedLookup string `json:"requested_lookup"`
2120
Network netip.Prefix `json:"network"`
2221
Record any `json:"record"`
2322
}
2423

25-
// Records returns an iterator over the records for the networks and
24+
// records returns an iterator over the records for the networks and
2625
// databases provided.
27-
func Records(
26+
func records(
2827
networks, databases []string,
2928
includeAliasedNetworks bool,
30-
) iter.Seq2[*Record, error] {
31-
return func(yield func(*Record, error) bool) {
29+
) iter.Seq2[*record, error] {
30+
return func(yield func(*record, error) bool) {
3231
for _, glob := range databases {
3332
matches, err := filepath.Glob(glob)
3433
if err != nil {
@@ -43,7 +42,7 @@ func Records(
4342
}
4443

4544
for _, thisNetwork := range networks {
46-
baseRecord := Record{
45+
baseRecord := record{
4746
DatabasePath: path,
4847
RequestedLookup: thisNetwork,
4948
}
@@ -64,8 +63,8 @@ func Records(
6463
func recordsForNetwork(
6564
reader *maxminddb.Reader,
6665
includeAliasedNetworks bool,
67-
record Record,
68-
yield func(*Record, error) bool,
66+
record record,
67+
yield func(*record, error) bool,
6968
) bool {
7069
var err error
7170
var network netip.Prefix
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package mmdbinspect
1+
package main
22

33
import (
44
"net/netip"
@@ -139,19 +139,19 @@ var country81_2_69_142 = map[string]any{
139139
},
140140
}
141141

142-
func TestAggregatedRecords(t *testing.T) {
142+
func TestRecords(t *testing.T) {
143143
tests := []struct {
144144
name string
145145
dbs []string
146146
networks []string
147-
expectRecords []Record
147+
expectRecords []record
148148
expectErr string
149149
}{
150150
{
151151
name: "multiple non-glob paths and multiple IPs",
152152
dbs: []string{CityDBPath, CountryDBPath},
153153
networks: []string{"81.2.69.142", "8.8.8.8"},
154-
expectRecords: []Record{
154+
expectRecords: []record{
155155
{
156156
DatabasePath: CityDBPath,
157157
RequestedLookup: "81.2.69.142",
@@ -170,7 +170,7 @@ func TestAggregatedRecords(t *testing.T) {
170170
name: "glob path",
171171
dbs: []string{filepath.Join(testDataDir, "GeoIP2-C*y-Test.mmdb")},
172172
networks: []string{"81.2.69.142"},
173-
expectRecords: []Record{
173+
expectRecords: []record{
174174
{
175175
DatabasePath: CityDBPath,
176176
RequestedLookup: "81.2.69.142",
@@ -212,8 +212,8 @@ func TestAggregatedRecords(t *testing.T) {
212212

213213
for _, test := range tests {
214214
t.Run(test.name, func(t *testing.T) {
215-
var records []Record
216-
for record, err := range Records(test.networks, test.dbs, false) {
215+
var recs []record
216+
for record, err := range records(test.networks, test.dbs, false) {
217217
// For now, we don't test errors that happen half way through an
218218
// iteration. If we want to in the future, we will need to rework
219219
// this a bit.
@@ -224,11 +224,11 @@ func TestAggregatedRecords(t *testing.T) {
224224
}
225225

226226
if err == nil {
227-
records = append(records, *record)
227+
recs = append(recs, *record)
228228
}
229229
}
230230

231-
assert.Equal(t, test.expectRecords, records)
231+
assert.Equal(t, test.expectRecords, recs)
232232
})
233233
}
234234
}

0 commit comments

Comments
 (0)