-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Closed
Labels
Description
Would be awesome if there was a Render function in context similar to rendering JSON.
Having this RendererFunc interface would allow to use any renderer. Would also be good to have html/template as a default Render. This is similar to how http.Handler and http.HandlerFunc is implemented.
type Renderer interface {
Render(w http.ResponseWriter, r *http.Request, status int, name string, data interface{})
}
type RendererFunc (w http.ResponseWriter, r *http.Request, status int, name string, data interface{})
func (f RendererFunc) Render(w http.ResponseWriter, r *http.Request, status int, name string, data interface{})gin use ... interface{} for data. Also should we also pass *http.Request to Render so that it can support content negotiation? If we pass request as nil then we can tell the render to not use content negotiation. Not sure if this is too much of magic. I think content negotiation should be a separate topic.
Here is sample api that could be possible to use. Thoughts?
var e := echo.New()
e.Get("/", func (c *e.Context) {
c.Render(http.StatusOK, "home", nil)
});