default_context.go
func (d *DefaultContext) Render(status int, rr render.Renderer) error {
	start := time.Now()
	defer func() {
		d.LogField("render", time.Since(start))
	}()
	if rr != nil {
		data := d.Data()
		pp := map[string]string{}
		for k, v := range d.params {
			pp[k] = v[0]
		}
		data["params"] = pp
		data["flash"] = d.Flash().data
		data["session"] = d.Session()
		data["request"] = d.Request()
		data["status"] = status
		bb := &bytes.Buffer{}

		err := rr.Render(bb, data)
		if err != nil {
			if er, ok := errors.Cause(err).(render.ErrRedirect); ok {
				return d.Redirect(er.Status, er.URL)
			}
			return HTTPError{Status: 500, Cause: err}
		}

		if d.Session() != nil {
			d.Flash().Clear()
			d.Flash().persist(d.Session())
		}

		d.Response().Header().Set("Content-Type", rr.ContentType())
		if p, ok := data["pagination"].(paginable); ok {
			d.Response().Header().Set("X-Pagination", p.Paginate())
		}
		d.Response().WriteHeader(status)
		_, err = io.Copy(d.Response(), bb)
		if err != nil {
			return HTTPError{Status: 500, Cause: err}
		}

		return nil
	}
	d.Response().WriteHeader(status)
	return nil
}
func (d *DefaultContext) Render(status int, rr render.Renderer) error {
	start := time.Now()
	defer func() {
		d.LogField("render", time.Since(start))
	}()
	if rr != nil {
		data := d.Data()
		pp := map[string]string{}
		for k, v := range d.params {
			pp[k] = v[0]
		}
		data["params"] = pp
		data["flash"] = d.Flash().data
		data["session"] = d.Session()
		data["request"] = d.Request()
		data["status"] = status
		bb := &bytes.Buffer{}

		err := rr.Render(bb, data)
		if err != nil {
			if er, ok := errors.Cause(err).(render.ErrRedirect); ok {
				return d.Redirect(er.Status, er.URL)
			}
			return HTTPError{Status: 500, Cause: err}
		}

		if d.Session() != nil {
			d.Flash().Clear()
			d.Flash().persist(d.Session())
		}

		d.Response().Header().Set("Content-Type", rr.ContentType())
		if p, ok := data["pagination"].(paginable); ok {
			d.Response().Header().Set("X-Pagination", p.Paginate())
		}
		d.Response().WriteHeader(status)
		_, err = io.Copy(d.Response(), bb)
		if err != nil {
			return HTTPError{Status: 500, Cause: err}
		}

		return nil
	}
	d.Response().WriteHeader(status)
	return nil
}
// Render a status code and render.Renderer to the associated Response.
// The request parameters will be made available to the render.Renderer
// "{{.params}}". Any values set onto the Context will also automatically
// be made available to the render.Renderer. To render "no content" pass
// in a nil render.Renderer.