Browse files

Merge remote branch 'mattetti/master' into develop

  • Loading branch information...
paulbellamy committed Jun 6, 2011
2 parents 36b8a65 + 263ca91 commit debab56f8e58039d0837564fa051c47ae9dedd33
Showing with 52 additions and 8 deletions.
  1. +52 −8 README.markdown
@@ -31,41 +31,46 @@ Where:
* mango.Headers is a map[string][]string of the response headers (similar to http.Header)
* mango.Body is a string for the response body
## Installation
$ goinstall
## Available Modules
* Sessions
Usage: Sessions(app_secret, cookie_name, cookie_domain string)
Usage: mango.Sessions(app_secret, cookie_name, cookie_domain string)
Basic session management. Provides a mango.Env.Session() helper which returns a map[string]interface{} representing the session. Any data stored in here will be serialized into the response session cookie.
* Logger
Usage: Logger(custom_logger \*log.Logger)
Usage: mango.Logger(custom_logger \*log.Logger)
Provides a way to set a custom log.Logger object for the app. If this middleware is not provided Mango will set up a default logger to os.Stdout for the app to log to.
* ShowErrors
Usage: ShowErrors(templateString string)
Usage: mango.ShowErrors(templateString string)
Catch any panics thrown from the app, and display them in an HTML template. If templateString is "", a default template is used. Not recommended to use the default template in production as it could provide information helpful to attackers.
* Routing
Usage: Routing(routes map[string]App)
Usage: mango.Routing(routes map[string]App)
"routes" is of the form { "/path1(.\*)": sub-stack1, "/path2(.\*)": sub-stack2 }. It lets us route different requests to different mango sub-stacks based on regexing the path.
* Static
Usage: Static(directory string)
Usage: mango.Static(directory string)
Serves static files from the directory provided.
Usage: JSONP
Usage: mango.JSONP
Provides JSONP support. If a request has a 'callback' parameter, and your application responds with a Content-Type of "application/json", the JSONP middleware will wrap the response in the callback function and set the Content-Type to "application/javascript".
@@ -74,7 +79,7 @@ Where:
package main
import (
func Hello(env mango.Env) (mango.Status, mango.Headers, mango.Body) {
@@ -85,7 +90,7 @@ Where:
func main() {
stack := new(mango.Stack)
stack.Address = ":3000"
@@ -183,6 +188,45 @@ To use our middleware we would do:
## Routing example
The following example routes "/hello" traffic to the hello handler and
"/bye" traffic to the bye handler, any other traffic goes to
routeNotFound handler returning a 404.
package main
func hello(env mango.Env) (mango.Status, mango.Headers, mango.Body) {
env.Logger().Println("Got a", env.Request().Method, "request for", env.Request().RawURL)
return 200, mango.Headers{}, mango.Body("Hello World!")
func bye(env mango.Env) (mango.Status, mango.Headers, mango.Body) {
return 200, mango.Headers{}, mango.Body("Bye Bye!")
func routeNotFound(env mango.Env) (mango.Status, mango.Headers, mango.Body) {
return 404, mango.Headers{}, mango.Body("You probably got lost :(")
func main() {
routes := make(map[string]mango.App)
routes["/hello"] = new(mango.Stack).Compile(hello)
routes["/bye"] = new(mango.Stack).Compile(bye)
testServer := new(mango.Stack)
testServer.Middleware(mango.ShowErrors("<html><body>{Error|html}</body></html>"), mango.Routing(routes))
testServer.Address = "localhost:3000"
fmt.Printf("Running server on: %s\n", testServer.Address)
## About
Mango was written by [Paul Bellamy](

0 comments on commit debab56

Please sign in to comment.