7e7a504421
- 配置加载包 config 更名为 configuration - 配置导出包 configexport 更名为 pce - 重构 config 包加载方式,采用加载器的方式,并且支持多加载器 - 重构 configexport 包,支持通过实现模板的方式导出不同格式的数据文件及结构文件
30 lines
542 B
Go
30 lines
542 B
Go
package tmpls
|
|
|
|
import (
|
|
"bytes"
|
|
jsonIter "github.com/json-iterator/go"
|
|
"github.com/kercylan98/minotaur/utils/str"
|
|
)
|
|
|
|
func NewJSON() *JSON {
|
|
return &JSON{
|
|
API: jsonIter.ConfigCompatibleWithStandardLibrary,
|
|
}
|
|
}
|
|
|
|
type JSON struct {
|
|
jsonIter.API
|
|
}
|
|
|
|
func (slf *JSON) Render(data map[any]any) (string, error) {
|
|
buffer := &bytes.Buffer{}
|
|
encoder := jsonIter.NewEncoder(buffer)
|
|
encoder.SetEscapeHTML(false)
|
|
encoder.SetIndent("", " ")
|
|
err := encoder.Encode(data)
|
|
if err != nil {
|
|
return str.None, err
|
|
}
|
|
return buffer.String(), nil
|
|
}
|