From a96acf6eed23e942253cfb3235890232ee521f55 Mon Sep 17 00:00:00 2001 From: John Guo Date: Mon, 22 Nov 2021 23:05:32 +0800 Subject: [PATCH] improve dump feature for package gutil --- util/gutil/gutil_dump.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/util/gutil/gutil_dump.go b/util/gutil/gutil_dump.go index 4572ce1d9..642a01161 100644 --- a/util/gutil/gutil_dump.go +++ b/util/gutil/gutil_dump.go @@ -122,11 +122,7 @@ func doDump(value interface{}, indent string, buffer *bytes.Buffer, option doDum doDumpString(exportInternalInput) case reflect.Bool: - if reflectValue.Bool() { - buffer.WriteString(`true`) - } else { - buffer.WriteString(`false`) - } + doDumpBool(exportInternalInput) case reflect.Int, @@ -357,6 +353,19 @@ func doDumpString(in doDumpInternalInput) { } } +func doDumpBool(in doDumpInternalInput) { + var s string + if in.ReflectValue.Bool() { + s = `true` + } else { + s = `false` + } + if in.Option.WithType { + s = fmt.Sprintf(`bool(%s)`, s) + } + in.Buffer.WriteString(s) +} + func doDumpDefault(in doDumpInternalInput) { s := fmt.Sprintf("%v", in.Value) s = gstr.Trim(s, `<>`)