import ( "github.com/go-martini/martini" "github.com/martini-contrib/render" ) func main() { m := martini.Classic() m.Use(render.Renderer(render.Options{ Directory: "/views", // specify the directory of templates Layout: "layout", // specify the layout file if needed Extensions: []string{".html"}, // specify the file extension of templates })) m.Get("/", func(r render.Render) { r.HTML(200, "index", "Hello, World!") }) m.Run() }
func main() { m := martini.Classic() m.Use(render.Renderer()) m.Get("/json", func(r render.Render) { r.JSON(200, map[string]interface{}{"message": "Hello, World!"}) }) m.Run() }In this example, we use the martini-contrib.render to render JSON. We call the `r.JSON` method to render a JSON response with a message. Overall, the github.com/martini-contrib.render package is a useful library for rendering templates in Go applications. It provides many options and features to make rendering templates more efficient and convenient.