Use a buffer in Render
This commit is contained in:
parent
890ff550eb
commit
717c6f65fc
11
context.go
11
context.go
@ -1,7 +1,9 @@
|
|||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
@ -76,9 +78,16 @@ func (c *Context) Render(code int, template string, data interface{}) error {
|
|||||||
panic(`Cannot call render without a renderer set`)
|
panic(`Cannot call render without a renderer set`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var b bytes.Buffer
|
||||||
|
err := c.router.Renderer.Render(&b, template, data, c)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
c.Response.Header().Set(`Content-Type`, `text/html`)
|
c.Response.Header().Set(`Content-Type`, `text/html`)
|
||||||
c.Response.WriteHeader(code)
|
c.Response.WriteHeader(code)
|
||||||
return c.router.Renderer.Render(c.Response, template, data, c)
|
_, _ = io.Copy(c.Response, &b)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set sets a value in the context. Set is not safe to be used concurrently
|
// Set sets a value in the context. Set is not safe to be used concurrently
|
||||||
|
Loading…
Reference in New Issue
Block a user