Skip to content

Commit 4592daf

Browse files
committed
Make the default output format JSONL
1 parent cbbb87c commit 4592daf

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

CHANGELOG.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
## 2.0.0
44

5-
* The output format has been flattened. When outputting to JSON, there is
6-
now one JSON object per line, containing the following keys: `database_path`,
7-
`requested_lookup`, `network`, and `record`. This allows for efficient
8-
streaming of large lookups, makes the key naming more consistent, and
9-
reduces the depth of the data structure.
5+
* The default output format is now YAML. This was done to improve the
6+
readability when using the tool as a standalone utility for doing lookups
7+
in an MMDB database. Use the `-jsonl` flag to output as JSONL instead.
8+
* When outputting as JSON, we now use JSONL. There is one JSON object per
9+
line.
10+
* The output format has been flattened. Each record that is output now
11+
contains the following keys: `database_path`, `requested_lookup`,
12+
`network`, and `record`. This allows for efficient streaming of large
13+
lookups, makes the key naming more consistent, and reduces the depth of
14+
the data structure.
1015
* Upgrade to `github.com/oschwald/maxminddb-golang/v2`. This is a breaking
1116
API change, but should not affect the use of the program.
1217
* You may now use a glob for the `-db` argument. If there are multiple

cmd/mmdbinspect/main.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"os"
1111
"strings"
1212

13+
"github.com/goccy/go-yaml"
1314
"github.com/maxmind/mmdbinspect/v2/pkg/mmdbinspect"
1415
)
1516

@@ -34,6 +35,8 @@ func main() {
3435
"Include aliased networks (e.g. 6to4, Teredo). This option may cause IPv4 networks to be listed more than once via aliases.", //nolint: lll
3536
)
3637

38+
useJSONL := flag.Bool("jsonl", false, "Output as JSONL instead of YAML")
39+
3740
flag.Usage = usage
3841
flag.Parse()
3942

@@ -52,7 +55,16 @@ func main() {
5255
os.Exit(1)
5356
}
5457

55-
encoder := json.NewEncoder(os.Stdout)
58+
w := os.Stdout
59+
60+
var encoder interface {
61+
Encode(any) error
62+
}
63+
if *useJSONL {
64+
encoder = json.NewEncoder(w)
65+
} else {
66+
encoder = yaml.NewEncoder(w)
67+
}
5668

5769
iterator := mmdbinspect.Records(network, mmdb, *includeAliasedNetworks)
5870

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/maxmind/mmdbinspect/v2
33
go 1.23
44

55
require (
6+
github.com/goccy/go-yaml v1.15.23
67
github.com/oschwald/maxminddb-golang/v2 v2.0.0-beta.3
78
github.com/stretchr/testify v1.10.0
89
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
22
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/goccy/go-yaml v1.15.23 h1:WS0GAX1uNPDLUvLkNU2vXq6oTnsmfVFocjQ/4qA48qo=
4+
github.com/goccy/go-yaml v1.15.23/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
35
github.com/oschwald/maxminddb-golang/v2 v2.0.0-beta.3 h1:dIygR/m/ArKzJy5HFVlDpBOG0hju03T+567HxrRRAF4=
46
github.com/oschwald/maxminddb-golang/v2 v2.0.0-beta.3/go.mod h1:JojXVel5ck1JzMiz32OVBfSk7lAtfSDUfzxIyVEuahM=
57
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

0 commit comments

Comments
 (0)