volatiletech / authboss

The boss of http auth.
MIT License
3.81k stars 207 forks source link

Use io.Writer instead of []byte in Render() method #240

Open frederikhors opened 5 years ago

frederikhors commented 5 years ago

Discussing with the great developer @valyala in thread https://github.com/valyala/quicktemplate/issues/58 about the amazing Authboss he gave us a suggestion to optimize a bit: https://github.com/valyala/quicktemplate/issues/58#issuecomment-517854569

As for the performance ... superfluous memory allocation when returning the byte slice from bytes.Buffer. The memory allocation could be avoided if Render() could accept io.Writer to write template output to.`

Can we just use io.Writer instead of []byte in Render() method?

aarondl commented 5 years ago

Although he's correct, the main reason for this to exist is to enable a JSON renderer which doesn't accept an io.Writer anywhere. I'm really not opposed to the change, but it would have to be a RenderWriter interface we upgrade to from a Renderer otherwise it'd break backwards compatability. I'd accept a PR for this, will not implement it myself.