top

Package render is a middleware for Martini that provides easy JSON serialization and HTML template rendering.

package main

import (
  "encoding/xml"

  "github.com/go-martini/martini"
  "github.com/martini-contrib/render"
)

type Greeting struct {
  XMLName xml.Name `xml:"greeting"`
  One     string   `xml:"one,attr"`
  Two     string   `xml:"two,attr"`
}

func main() {
  m := martini.Classic()
  m.Use(render.Renderer()) // reads "templates" directory by default

  m.Get("/html", func(r render.Render) {
    r.HTML(200, "mytemplate", nil)
  })

  m.Get("/json", func(r render.Render) {
    r.JSON(200, "hello world")
  })

  m.Get("/xml", func(r render.Render) {
    r.XML(200, Greeting{One: "hello", Two: "world"})
  })

  m.Run()
}

Imported by 2 package(s)

  1. github.com/abijr/Kails
  2. github.com/abijr/Kails/middleware

Imports 3 package(s)

  1. github.com/go-martini/martini
  2. github.com/nicksnyder/go-i18n/i18n
  3. github.com/nicksnyder/go-i18n/i18n/language