config: Use MarshalIndent for config.
This commit is contained in:
+13
-2
@@ -22,8 +22,19 @@ func DecodeJsonConfig(r io.Reader, v interface{}) error {
|
|||||||
|
|
||||||
// Simple JSON based configuration encoder.
|
// Simple JSON based configuration encoder.
|
||||||
func EncodeJsonConfig(w io.Writer, v interface{}) error {
|
func EncodeJsonConfig(w io.Writer, v interface{}) error {
|
||||||
e := json.NewEncoder(w)
|
bb, err := json.MarshalIndent(v, "", "\t")
|
||||||
return e.Encode(v)
|
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,
|
// Return a configuration file path. If baseName is empty,
|
||||||
|
|||||||
Reference in New Issue
Block a user