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