Skip to content

Commit 0733292

Browse files
authored
chore: json encoder cleanup (#106)
1 parent 024a529 commit 0733292

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

engine.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type HTML struct {
3434
bp GenericBufferPool
3535
}
3636

37-
// JSONEncoder match encoding/json.Encoder capabilities.
37+
// JSONEncoder is the interface for encoding/json.Encoder.
3838
type JSONEncoder interface {
3939
Encode(v interface{}) error
4040
SetEscapeHTML(on bool)
@@ -48,7 +48,7 @@ type JSON struct {
4848
UnEscapeHTML bool
4949
Prefix []byte
5050
StreamingJSON bool
51-
NewEncoder func(w io.Writer) JSONEncoder
51+
Encoder func(w io.Writer) JSONEncoder
5252
}
5353

5454
// JSONP built-in renderer.
@@ -122,7 +122,7 @@ func (j JSON) Render(w io.Writer, v interface{}) error {
122122
}
123123

124124
var buf bytes.Buffer
125-
encoder := j.NewEncoder(&buf)
125+
encoder := j.Encoder(&buf)
126126
encoder.SetEscapeHTML(!j.UnEscapeHTML)
127127

128128
if j.Indent {
@@ -163,7 +163,7 @@ func (j JSON) renderStreamingJSON(w io.Writer, v interface{}) error {
163163
_, _ = w.Write(j.Prefix)
164164
}
165165

166-
encoder := j.NewEncoder(w)
166+
encoder := j.Encoder(w)
167167
encoder.SetEscapeHTML(!j.UnEscapeHTML)
168168

169169
if j.Indent {

render.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ type Options struct {
118118
// BufferPool to use when rendering HTML templates. If none is supplied
119119
// defaults to SizedBufferPool of size 32 with 512KiB buffers.
120120
BufferPool GenericBufferPool
121-
// Custom JSON Encoder. Default to encoding/json.NewEncoder.
121+
// Custom JSON Encoder. Defaults to encoding/json.NewEncoder.
122122
JSONEncoder func(w io.Writer) JSONEncoder
123123
}
124124

@@ -535,7 +535,7 @@ func (r *Render) JSON(w io.Writer, status int, v interface{}) error {
535535
Prefix: r.opt.PrefixJSON,
536536
UnEscapeHTML: r.opt.UnEscapeHTML,
537537
StreamingJSON: r.opt.StreamingJSON,
538-
NewEncoder: r.opt.JSONEncoder,
538+
Encoder: r.opt.JSONEncoder,
539539
}
540540

541541
return r.Render(w, j, v)

0 commit comments

Comments
 (0)