Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: json encoder cleanup #106

Merged
merged 1 commit into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

// Engine is the generic interface for all responses.
type Engine interface {
Render(io.Writer, interface{}) error

Check failure on line 14 in engine.go

View workflow job for this annotation

GitHub Actions / golangci

interface method Render must have named param for type io.Writer (inamedparam)
}

// Head defines the basic ContentType and Status fields.
Expand All @@ -34,7 +34,7 @@
bp GenericBufferPool
}

// JSONEncoder match encoding/json.Encoder capabilities.
// JSONEncoder is the interface for encoding/json.Encoder.
type JSONEncoder interface {
Encode(v interface{}) error
SetEscapeHTML(on bool)
Expand All @@ -48,7 +48,7 @@
UnEscapeHTML bool
Prefix []byte
StreamingJSON bool
NewEncoder func(w io.Writer) JSONEncoder
Encoder func(w io.Writer) JSONEncoder
}

// JSONP built-in renderer.
Expand Down Expand Up @@ -122,7 +122,7 @@
}

var buf bytes.Buffer
encoder := j.NewEncoder(&buf)
encoder := j.Encoder(&buf)
encoder.SetEscapeHTML(!j.UnEscapeHTML)

if j.Indent {
Expand Down Expand Up @@ -163,7 +163,7 @@
_, _ = w.Write(j.Prefix)
}

encoder := j.NewEncoder(w)
encoder := j.Encoder(w)
encoder.SetEscapeHTML(!j.UnEscapeHTML)

if j.Indent {
Expand Down
4 changes: 2 additions & 2 deletions render.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
// BufferPool to use when rendering HTML templates. If none is supplied
// defaults to SizedBufferPool of size 32 with 512KiB buffers.
BufferPool GenericBufferPool
// Custom JSON Encoder. Default to encoding/json.NewEncoder.
// Custom JSON Encoder. Defaults to encoding/json.NewEncoder.
JSONEncoder func(w io.Writer) JSONEncoder
}

Expand Down Expand Up @@ -260,7 +260,7 @@
if info != nil && watcher != nil {
_ = watcher.Add(path)
}
if info == nil || info.IsDir() {

Check failure on line 263 in render.go

View workflow job for this annotation

GitHub Actions / golangci

if statements should only be cuddled with assignments (wsl)
return nil
}

Expand Down Expand Up @@ -535,7 +535,7 @@
Prefix: r.opt.PrefixJSON,
UnEscapeHTML: r.opt.UnEscapeHTML,
StreamingJSON: r.opt.StreamingJSON,
NewEncoder: r.opt.JSONEncoder,
Encoder: r.opt.JSONEncoder,
}

return r.Render(w, j, v)
Expand Down
Loading