Ai
1 Star 0 Fork 0

go-better/go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
marshal_indent.go 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
proce 提交于 2022-03-24 11:57 +08:00 . 迁移完成
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package json implements encoding and decoding of JSON as defined in
// RFC 7159. The mapping between JSON and Go values is described
// in the documentation for the Marshal and Unmarshal functions.
//
// See "JSON and Go" for an introduction to this package:
// https://golang.org/doc/articles/json_and_go.html
package jsondoc
import (
"bytes"
"gitee.com/go-better/dev/encoding/jsondoc/encoder"
"gitee.com/go-better/dev/encoding/jsondoc/scanner"
)
// MarshalIndent is like json.Marshal but applies Indent to format the output.
// Each JSON element in the output will begin on a new line beginning with prefix
// followed by one or more copies of indent according to the indentation nesting.
func MarshalIndent(v interface{}, escapeHTML bool, prefix, indent string) ([]byte, error) {
b, err := encoder.Marshal(v, escapeHTML)
if err != nil {
return nil, err
}
var buf bytes.Buffer
err = scanner.Indent(&buf, b, prefix, indent)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/go-better/go.git
git@gitee.com:go-better/go.git
go-better
go
go
d31700df43a9

搜索帮助