Skip to content

goforgery/compose

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

compose

Build Status

Page composer for Forgery2.

Install

go get github.com/goforgery/compose

Use

Compose takes a map of Forgery2 handler functions indexed by a string. The map is then executed returning a new map where each functions return string is set as the value for the aforementioned index.

package main

import (
	"github.com/goforgery/compose"
	"github.com/goforgery/forgery2"
	"github.com/goforgery/mustache"
)

func main() {
	app := f.CreateApp()
	app.Engine(".html", mustache.Create())
	app.Get("/", func(req *f.Request, res *f.Response, next func()) {
		c := compose.Map{
			"header": func(req *f.Request, res *f.Response, next func()) {
				res.Send("Header string")
			},
			"body": func(req *f.Request, res *f.Response, next func()) {
				res.Render("body.html", "Title")
			},
			"footer": func(req *f.Request, res *f.Response, next func()) {
				res.End("Footer string")
			},
			"tail": func(req *f.Request, res *f.Response, next func()) {
				res.Write("Tail string")
			},
			"close": func(req *f.Request, res *f.Response, next func()) {
				res.WriteBytes([]byte("Close string"))
			},
		}
		data := c.Execute(req, res, next)
		res.Render("index.html", data)
	})
	app.Listen(3000)
}

Test

go test

About

Page composer for Forgery2.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages