Skip to content

Commit eb71152

Browse files
committed
optimize json output
1 parent c237e51 commit eb71152

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

describe/utils.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/ghodss/yaml"
99
"github.com/jedib0t/go-pretty/v6/table"
10+
1011
corepb "github.com/projecteru2/core/rpc/gen"
1112
)
1213

@@ -56,16 +57,20 @@ func describeAsJSON(o interface{}) {
5657
}
5758

5859
func describeChNodeAsJSON(ch chan *corepb.Node) {
60+
nodes := []*corepb.Node{}
5961
for t := range ch {
60-
j, _ := json.MarshalIndent(t, "", " ")
61-
fmt.Println(string(j))
62+
nodes = append(nodes, t)
6263
}
64+
j, _ := json.MarshalIndent(nodes, "", " ")
65+
fmt.Println(string(j))
6366
}
6467
func describeChNodeResourceAsJSON(ch chan *corepb.NodeResource) {
68+
nodes := []*corepb.NodeResource{}
6569
for t := range ch {
66-
j, _ := json.MarshalIndent(t, "", " ")
67-
fmt.Println(string(j))
70+
nodes = append(nodes, t)
6871
}
72+
j, _ := json.MarshalIndent(nodes, "", " ")
73+
fmt.Println(string(j))
6974
}
7075

7176
func describeAsYAML(o interface{}) {

0 commit comments

Comments
 (0)