revert manual json marshal
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
35
main.go
35
main.go
@@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
@@ -9,7 +8,6 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -398,39 +396,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Output final results in JSON
|
// Output final results in JSON
|
||||||
// TODO - manually generate JSON since Marshal doesn't care about field ordering
|
|
||||||
if len(combined) > 0 {
|
if len(combined) > 0 {
|
||||||
var b []byte
|
j, _ := json.Marshal(combined)
|
||||||
buf := bytes.NewBuffer(b)
|
fmt.Println(string(j))
|
||||||
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))
|
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("{}")
|
fmt.Println("{}")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user