fixed printArray function
This commit is contained in:
parent
a2031d2e0c
commit
7ab3b8d2b1
30
main.go
30
main.go
@ -10,15 +10,17 @@ import (
|
||||
// Print will beautify the output of body
|
||||
func Print(body interface{}) {
|
||||
b, err := json.Marshal(body)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var obj map[string]interface{}
|
||||
//json.Unmarshal([]byte(body), &obj)
|
||||
json.Unmarshal(b, &obj)
|
||||
|
||||
// Make a custom formatter with indent set
|
||||
f := colorjson.NewFormatter()
|
||||
f.Indent = 2
|
||||
|
||||
// Marshall the Colorized JSON
|
||||
// Marshal the Colorized JSON
|
||||
s, err := f.Marshal(obj)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -29,8 +31,26 @@ func Print(body interface{}) {
|
||||
}
|
||||
|
||||
// PrintArray will beautify the output of an interface array (bodyArray)
|
||||
func PrintArray(bodyArray []interface{}) {
|
||||
for i := range bodyArray {
|
||||
Print(bodyArray[i])
|
||||
func PrintArray(bodyArray interface{}) {
|
||||
b, err := json.Marshal(bodyArray)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var obj []map[string]interface{}
|
||||
json.Unmarshal(b, &obj)
|
||||
|
||||
// Make a custom formatter with indent set
|
||||
f := colorjson.NewFormatter()
|
||||
f.Indent = 2
|
||||
|
||||
for i := range obj {
|
||||
// Marshal the Colorized JSON
|
||||
s, err := f.Marshal(obj[i])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// Print out string to stdout
|
||||
fmt.Println(string(s))
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user