From 3b737db0351b9e3966ae7e92f044928b1371cf16 Mon Sep 17 00:00:00 2001 From: mzz2017 <2017@duck.com> Date: Tue, 20 Jun 2023 22:51:31 +0800 Subject: [PATCH] feat(config): support IgnoreZero option for config.Marhsaller --- config/marshal.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/marshal.go b/config/marshal.go index 914f2afe58..ab1faf9ece 100644 --- a/config/marshal.go +++ b/config/marshal.go @@ -38,6 +38,7 @@ func (c *Config) Marshal(indentSpace int) (b []byte, err error) { type Marshaller struct { IndentSpace int + IgnoreZero bool buf bytes.Buffer } @@ -138,7 +139,7 @@ unsupported: } func (m *Marshaller) marshalLeaf(key string, from reflect.Value, depth int) (err error) { - if from.IsZero() { + if m.IgnoreZero && from.IsZero() { // Do not marshal zero value. return nil }