mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Use MarshalIndent instead of marshal and indent
This commit is contained in:
parent
5962874414
commit
7d3cad6898
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package dns
|
package dns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -37,18 +36,11 @@ func NewTreeCache() *TreeCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cache *TreeCache) Serialize() (string, error) {
|
func (cache *TreeCache) Serialize() (string, error) {
|
||||||
b, err := json.Marshal(cache)
|
prettyJSON, err := json.MarshalIndent(cache, "", "\t")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
return string(prettyJSON), nil
|
||||||
var prettyJSON bytes.Buffer
|
|
||||||
err = json.Indent(&prettyJSON, b, "", "\t")
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return string(prettyJSON.Bytes()), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// setEntry creates the entire path if it doesn't already exist in the cache,
|
// setEntry creates the entire path if it doesn't already exist in the cache,
|
||||||
|
@ -267,14 +267,12 @@ func (p *JSONPrinter) PrintObj(obj runtime.Object, w io.Writer) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := json.Marshal(obj)
|
data, err := json.MarshalIndent(obj, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
dst := bytes.Buffer{}
|
data = append(data, '\n')
|
||||||
err = json.Indent(&dst, data, "", " ")
|
_, err = w.Write(data)
|
||||||
dst.WriteByte('\n')
|
|
||||||
_, err = w.Write(dst.Bytes())
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user