revert manual json marshal
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-05-24 14:18:31 +10:00
parent 7eb46172b7
commit fbf795b586

35
main.go
View File

@@ -1,7 +1,6 @@
package main
import (
"bytes"
"context"
"encoding/json"
"flag"
@@ -9,7 +8,6 @@ import (
"log"
"net/url"
"os"
"reflect"
"sort"
"strings"
"time"
@@ -398,39 +396,10 @@ func main() {
}
// Output final results in JSON
// TODO - manually generate JSON since Marshal doesn't care about field ordering
if len(combined) > 0 {
var b []byte
buf := bytes.NewBuffer(b)
buf.WriteRune('{')
l := len(combined)
for i, entry := range combined {
v := reflect.ValueOf(entry)
t := v.Type()
for j := 0; j < v.NumField(); j++ {
field := v.Field(j)
fieldType := t.Field(j)
km, _ := json.Marshal(fieldType.Name)
buf.Write(km)
buf.WriteRune(':')
vm, _ := json.Marshal(field.Interface())
buf.Write(vm)
if i != l-1 {
buf.WriteRune(',')
}
}
}
buf.WriteRune('}')
fmt.Println(buf.String())
//j, _ := json.Marshal(combined)
//fmt.Println(string(j))
j, _ := json.Marshal(combined)
fmt.Println(string(j))
} else {
fmt.Println("{}")
}
}