From eb7115267ebc52cf5a81d7e66ba79d8b024afad6 Mon Sep 17 00:00:00 2001 From: DuodenumL Date: Mon, 18 Jul 2022 17:42:55 +0800 Subject: [PATCH] optimize json output --- describe/utils.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/describe/utils.go b/describe/utils.go index a7bd0ec..d664e99 100644 --- a/describe/utils.go +++ b/describe/utils.go @@ -7,6 +7,7 @@ import ( "github.com/ghodss/yaml" "github.com/jedib0t/go-pretty/v6/table" + corepb "github.com/projecteru2/core/rpc/gen" ) @@ -56,16 +57,20 @@ func describeAsJSON(o interface{}) { } func describeChNodeAsJSON(ch chan *corepb.Node) { + nodes := []*corepb.Node{} for t := range ch { - j, _ := json.MarshalIndent(t, "", " ") - fmt.Println(string(j)) + nodes = append(nodes, t) } + j, _ := json.MarshalIndent(nodes, "", " ") + fmt.Println(string(j)) } func describeChNodeResourceAsJSON(ch chan *corepb.NodeResource) { + nodes := []*corepb.NodeResource{} for t := range ch { - j, _ := json.MarshalIndent(t, "", " ") - fmt.Println(string(j)) + nodes = append(nodes, t) } + j, _ := json.MarshalIndent(nodes, "", " ") + fmt.Println(string(j)) } func describeAsYAML(o interface{}) {