Skip to content

Instantly share code, notes, and snippets.

@mattetti
Created June 6, 2011 01:41
Show Gist options
  • Save mattetti/1009624 to your computer and use it in GitHub Desktop.
Save mattetti/1009624 to your computer and use it in GitHub Desktop.
mango routed sample app example
package main
import(
"github.com/paulbellamy/mango"
"fmt"
)
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"
testServer.Run(routeNotFound)
fmt.Printf("Running server on: %s\n", testServer.Address)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment