New rendering pipeline
This commit is contained in:
		
							
								
								
									
										31
									
								
								context.go
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								context.go
									
									
									
									
									
								
							@ -324,15 +324,18 @@ func (c *Context) Header(key, value string) {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *Context) Render(code int, r render.Render) {
 | 
			
		||||
	w := c.Writer
 | 
			
		||||
	w.WriteHeader(code)
 | 
			
		||||
	if err := r.Write(w); err != nil {
 | 
			
		||||
func (c *Context) Return(code int, r render.Render) {
 | 
			
		||||
	c.Writer.WriteHeader(code)
 | 
			
		||||
	c.Render(r)
 | 
			
		||||
	c.Abort()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *Context) Render(r render.Render) {
 | 
			
		||||
	if err := r.Write(c.Writer); err != nil {
 | 
			
		||||
		debugPrintError(err)
 | 
			
		||||
		c.ErrorTyped(err, ErrorTypeInternal, nil)
 | 
			
		||||
		c.AbortWithStatus(500)
 | 
			
		||||
	}
 | 
			
		||||
	//c.Abort()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Renders the HTTP template specified by its file name.
 | 
			
		||||
@ -340,28 +343,28 @@ func (c *Context) Render(code int, r render.Render) {
 | 
			
		||||
// See http://golang.org/doc/articles/wiki/
 | 
			
		||||
func (c *Context) HTML(code int, name string, obj interface{}) {
 | 
			
		||||
	instance := c.Engine.HTMLRender.Instance(name, obj)
 | 
			
		||||
	c.Render(code, instance)
 | 
			
		||||
	c.Return(code, instance)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *Context) IndentedJSON(code int, obj interface{}) {
 | 
			
		||||
	c.Render(code, render.IndentedJSON{Data: obj})
 | 
			
		||||
	c.Return(code, render.IndentedJSON{Data: obj})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 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".
 | 
			
		||||
func (c *Context) JSON(code int, obj interface{}) {
 | 
			
		||||
	c.Render(code, render.JSON{Data: obj})
 | 
			
		||||
	c.Return(code, render.JSON{Data: obj})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 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".
 | 
			
		||||
func (c *Context) XML(code int, obj interface{}) {
 | 
			
		||||
	c.Render(code, render.XML{Data: obj})
 | 
			
		||||
	c.Return(code, render.XML{Data: obj})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 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{}) {
 | 
			
		||||
	c.Render(code, render.String{
 | 
			
		||||
	c.Return(code, render.String{
 | 
			
		||||
		Format: format,
 | 
			
		||||
		Data:   values},
 | 
			
		||||
	)
 | 
			
		||||
@ -369,7 +372,7 @@ func (c *Context) String(code int, format string, values ...interface{}) {
 | 
			
		||||
 | 
			
		||||
// Returns a HTTP redirect to the specific location.
 | 
			
		||||
func (c *Context) Redirect(code int, location string) {
 | 
			
		||||
	c.Render(-1, render.Redirect{
 | 
			
		||||
	c.Render(render.Redirect{
 | 
			
		||||
		Code:     code,
 | 
			
		||||
		Location: location,
 | 
			
		||||
		Request:  c.Request,
 | 
			
		||||
@ -378,7 +381,7 @@ func (c *Context) Redirect(code int, location string) {
 | 
			
		||||
 | 
			
		||||
// Writes some data into the body stream and updates the HTTP code.
 | 
			
		||||
func (c *Context) Data(code int, contentType string, data []byte) {
 | 
			
		||||
	c.Render(code, render.Data{
 | 
			
		||||
	c.Return(code, render.Data{
 | 
			
		||||
		ContentType: contentType,
 | 
			
		||||
		Data:        data,
 | 
			
		||||
	})
 | 
			
		||||
@ -386,14 +389,14 @@ func (c *Context) Data(code int, contentType string, data []byte) {
 | 
			
		||||
 | 
			
		||||
// Writes the specified file into the body stream
 | 
			
		||||
func (c *Context) File(filepath string) {
 | 
			
		||||
	c.Render(-1, render.File{
 | 
			
		||||
	c.Return(-1, render.File{
 | 
			
		||||
		Path:    filepath,
 | 
			
		||||
		Request: c.Request,
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *Context) SSEvent(name string, message interface{}) {
 | 
			
		||||
	c.Render(-1, sse.Event{
 | 
			
		||||
	c.Render(sse.Event{
 | 
			
		||||
		Event: name,
 | 
			
		||||
		Data:  message,
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user