-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsondump.go
More file actions
52 lines (46 loc) · 958 Bytes
/
jsondump.go
File metadata and controls
52 lines (46 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"encoding/json"
"fmt"
"log/slog"
"os"
"github.com/abh/geodns/v3/querylog"
"github.com/hamba/avro/v2/ocf"
"go.ntppool.org/common/logger"
)
func dumpJSON(files []string) {
log := logger.Setup()
for _, fileName := range files {
err := readFile(log, fileName)
if err != nil {
log.Error("could not read file", "err", err)
}
}
}
func readFile(log *slog.Logger, fileName string) error {
log = log.With("file", fileName)
fh, err := os.Open(fileName)
if err != nil {
return err
}
defer fh.Close()
dec, err := ocf.NewDecoder(fh)
if err != nil {
return fmt.Errorf("could not setup decoder: %w", err)
}
for dec.HasNext() {
e := querylog.Entry{}
err := dec.Decode(&e)
if err != nil {
log.Warn("could not decode entry", "err", err)
continue
}
js, err := json.Marshal(e)
if err != nil {
log.Warn("could not marshal json", "err", err)
continue
}
fmt.Printf("%s\n", js)
}
return nil
}