Files
gitea/modules/templates/util_json.go
silverwind 13406e7aa7 chore: update and relax revive naming rules (#38615)
- enable `skip-initialism-name-checks`, so names like `sessionUid` are
allowed
- replace removed `skip-package-name-checks` option with new
`package-naming` with fitting rules for gitea
- drop dead exclusion paths
2026-07-24 21:47:23 +00:00

36 lines
580 B
Go

// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package templates
import (
"bytes"
"gitea.dev/modules/json"
)
type JsonUtils struct{}
var jsonUtils = JsonUtils{}
func NewJsonUtils() *JsonUtils {
return &jsonUtils
}
func (su *JsonUtils) EncodeToString(v any) string {
out, err := json.Marshal(v)
if err != nil {
return ""
}
return string(out)
}
func (su *JsonUtils) PrettyIndent(s string) string {
var out bytes.Buffer
err := json.Indent(&out, []byte(s), "", " ")
if err != nil {
return ""
}
return out.String()
}