Documentation ¶
Overview ¶
Package render is a middleware for Martini that provides easy JSON serialization and HTML template rendering.
package main import ( "github.com/codegangsta/martini" "github.com/codegangsta/martini-contrib/render" ) func main() { m := martini.Classic() m.Use(render.Renderer("templates")) m.Get("/html", func(r render.Render) { r.HTML(200, "mytemplate.tmpl", nil) }) m.Get("/json", func(r render.Render) { r.JSON(200, "hello world") }) m.Run() }
Index ¶
Constants ¶
View Source
const ( ContentType = "Content-Type" ContentJSON = "application/json" ContentHTML = "text/html" )
Variables ¶
This section is empty.
Functions ¶
func Renderer ¶
Renderer is a Middleware that maps a render.Render service into the Martini handler chain. Renderer will compile templates globbed in the given dir. Templates must have the .tmpl extension to be compiled.
If MARTINI_ENV is set to "" or "development" then templates will be recompiled on every request. For more performance, set the MARTINI_ENV environment variable to "production"
Types ¶
type Render ¶
type Render interface { // JSON writes the given status and JSON serialized version of the given value to the http.ResponseWriter. JSON(status int, v interface{}) // HTML renders a html template specified by the name and writes the result and given status to the http.ResponseWriter. HTML(status int, name string, v interface{}) }
Render is a service that can be injected into a Martini handler. Render provides functions for easily writing JSON and HTML templates out to a http Response.
Click to show internal directories.
Click to hide internal directories.