diff --git a/engine.go b/engine.go index afeff96..db32d48 100644 --- a/engine.go +++ b/engine.go @@ -34,7 +34,7 @@ type HTML struct { 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) @@ -48,7 +48,7 @@ type JSON struct { UnEscapeHTML bool Prefix []byte StreamingJSON bool - NewEncoder func(w io.Writer) JSONEncoder + Encoder func(w io.Writer) JSONEncoder } // JSONP built-in renderer. @@ -122,7 +122,7 @@ func (j JSON) Render(w io.Writer, v interface{}) error { } var buf bytes.Buffer - encoder := j.NewEncoder(&buf) + encoder := j.Encoder(&buf) encoder.SetEscapeHTML(!j.UnEscapeHTML) if j.Indent { @@ -163,7 +163,7 @@ func (j JSON) renderStreamingJSON(w io.Writer, v interface{}) error { _, _ = w.Write(j.Prefix) } - encoder := j.NewEncoder(w) + encoder := j.Encoder(w) encoder.SetEscapeHTML(!j.UnEscapeHTML) if j.Indent { diff --git a/render.go b/render.go index 9f48b8c..8ab3c63 100644 --- a/render.go +++ b/render.go @@ -118,7 +118,7 @@ type Options struct { // 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 } @@ -535,7 +535,7 @@ func (r *Render) JSON(w io.Writer, status int, v interface{}) error { 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)