From ac6e3972cfc41bc8d299996d94383462dcd89da6 Mon Sep 17 00:00:00 2001 From: Daniel Theophanes Date: Sat, 21 Sep 2013 10:46:33 -0700 Subject: [PATCH] config: Use MarshalIndent for config. --- config/config.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/config/config.go b/config/config.go index ae33182..375b89e 100644 --- a/config/config.go +++ b/config/config.go @@ -22,8 +22,19 @@ func DecodeJsonConfig(r io.Reader, v interface{}) error { // Simple JSON based configuration encoder. func EncodeJsonConfig(w io.Writer, v interface{}) error { - e := json.NewEncoder(w) - return e.Encode(v) + bb, err := json.MarshalIndent(v, "", "\t") + if err != nil { + return err + } + n, tot := 0, 0 + for { + n, err = w.Write(bb[tot:]) + tot += n + if len(bb) == tot { + break + } + } + return err } // Return a configuration file path. If baseName is empty,