Drops c.Return() API

This commit is contained in:
Manu Mtz-Almeida 2015-05-18 20:51:52 +02:00
parent afb32ac6ac
commit 6313545df7
1 changed files with 10 additions and 15 deletions

View File

@ -324,13 +324,8 @@ func (c *Context) Header(key, value string) {
} }
} }
func (c *Context) Return(code int, r render.Render) { func (c *Context) Render(code int, r render.Render) {
c.Writer.WriteHeader(code) c.Writer.WriteHeader(code)
c.Render(r)
c.Abort()
}
func (c *Context) Render(r render.Render) {
if err := r.Write(c.Writer); err != nil { if err := r.Write(c.Writer); err != nil {
debugPrintError(err) debugPrintError(err)
c.ErrorTyped(err, ErrorTypeInternal, nil) c.ErrorTyped(err, ErrorTypeInternal, nil)
@ -343,28 +338,28 @@ func (c *Context) Render(r render.Render) {
// See http://golang.org/doc/articles/wiki/ // See http://golang.org/doc/articles/wiki/
func (c *Context) HTML(code int, name string, obj interface{}) { func (c *Context) HTML(code int, name string, obj interface{}) {
instance := c.Engine.HTMLRender.Instance(name, obj) instance := c.Engine.HTMLRender.Instance(name, obj)
c.Return(code, instance) c.Render(code, instance)
} }
func (c *Context) IndentedJSON(code int, obj interface{}) { func (c *Context) IndentedJSON(code int, obj interface{}) {
c.Return(code, render.IndentedJSON{Data: obj}) c.Render(code, render.IndentedJSON{Data: obj})
} }
// Serializes the given struct as JSON into the response body in a fast and efficient way. // Serializes the given struct as JSON into the response body in a fast and efficient way.
// It also sets the Content-Type as "application/json". // It also sets the Content-Type as "application/json".
func (c *Context) JSON(code int, obj interface{}) { func (c *Context) JSON(code int, obj interface{}) {
c.Return(code, render.JSON{Data: obj}) c.Render(code, render.JSON{Data: obj})
} }
// Serializes the given struct as XML into the response body in a fast and efficient way. // Serializes the given struct as XML into the response body in a fast and efficient way.
// It also sets the Content-Type as "application/xml". // It also sets the Content-Type as "application/xml".
func (c *Context) XML(code int, obj interface{}) { func (c *Context) XML(code int, obj interface{}) {
c.Return(code, render.XML{Data: obj}) c.Render(code, render.XML{Data: obj})
} }
// Writes the given string into the response body and sets the Content-Type to "text/plain". // Writes the given string into the response body and sets the Content-Type to "text/plain".
func (c *Context) String(code int, format string, values ...interface{}) { func (c *Context) String(code int, format string, values ...interface{}) {
c.Return(code, render.String{ c.Render(code, render.String{
Format: format, Format: format,
Data: values}, Data: values},
) )
@ -372,7 +367,7 @@ func (c *Context) String(code int, format string, values ...interface{}) {
// Returns a HTTP redirect to the specific location. // Returns a HTTP redirect to the specific location.
func (c *Context) Redirect(code int, location string) { func (c *Context) Redirect(code int, location string) {
c.Render(render.Redirect{ c.Render(-1, render.Redirect{
Code: code, Code: code,
Location: location, Location: location,
Request: c.Request, Request: c.Request,
@ -381,7 +376,7 @@ func (c *Context) Redirect(code int, location string) {
// Writes some data into the body stream and updates the HTTP code. // Writes some data into the body stream and updates the HTTP code.
func (c *Context) Data(code int, contentType string, data []byte) { func (c *Context) Data(code int, contentType string, data []byte) {
c.Return(code, render.Data{ c.Render(code, render.Data{
ContentType: contentType, ContentType: contentType,
Data: data, Data: data,
}) })
@ -389,14 +384,14 @@ func (c *Context) Data(code int, contentType string, data []byte) {
// Writes the specified file into the body stream // Writes the specified file into the body stream
func (c *Context) File(filepath string) { func (c *Context) File(filepath string) {
c.Return(-1, render.File{ c.Render(-1, render.File{
Path: filepath, Path: filepath,
Request: c.Request, Request: c.Request,
}) })
} }
func (c *Context) SSEvent(name string, message interface{}) { func (c *Context) SSEvent(name string, message interface{}) {
c.Render(sse.Event{ c.Render(-1, sse.Event{
Event: name, Event: name,
Data: message, Data: message,
}) })