From 33ce7169d0c8a67a4401bee94015ed60252a00aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Tue, 4 Apr 2023 16:30:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E5=8F=B0=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- console.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/console.go b/console.go index 620f999..8e1c1a2 100644 --- a/console.go +++ b/console.go @@ -8,6 +8,7 @@ package util import ( + "bytes" "encoding/json" "fmt" "reflect" @@ -49,11 +50,9 @@ func (c *console) Output(dataList ...interface{}) { if !c.enable { return } - list := make([]interface{}, 0) - for _, item := range dataList { - list = append(list, c.getDataStr(item)) + for idx, item := range dataList { + fmt.Println(fmt.Sprintf("%v --> %v", idx, c.getDataStr(item))) } - fmt.Println(list...) } // getDataStr 数据转换为字符串 @@ -79,12 +78,13 @@ func (c *console) getDataStr(data interface{}) string { case reflect.Array: fallthrough case reflect.Struct: + var out bytes.Buffer byteData, _ := json.Marshal(data) - return string(byteData) + _ = json.Indent(&out, []byte(string(byteData)+"\n"), "", "\t") + return string(out.Bytes()) case reflect.Func: return dataValue.String() default: return fmt.Sprintf("%v", data) } - return "" }