mirror of
https://github.com/jimeh/go-render.git
synced 2026-02-19 03:16:39 +00:00
refactor: yet another one, someday I might be happy
This commit is contained in:
12
json.go
12
json.go
@@ -24,11 +24,11 @@ type JSON struct {
|
||||
var _ FormatRenderer = (*JSON)(nil)
|
||||
|
||||
// Render marshals the given value to JSON.
|
||||
func (j *JSON) Render(w io.Writer, v any) error {
|
||||
func (jr *JSON) Render(w io.Writer, v any) error {
|
||||
enc := json.NewEncoder(w)
|
||||
if j.Pretty {
|
||||
prefix := j.Prefix
|
||||
indent := j.Indent
|
||||
if jr.Pretty {
|
||||
prefix := jr.Prefix
|
||||
indent := jr.Indent
|
||||
if indent == "" {
|
||||
indent = " "
|
||||
}
|
||||
@@ -43,3 +43,7 @@ func (j *JSON) Render(w io.Writer, v any) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (jr *JSON) Formats() []string {
|
||||
return []string{"json"}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user