func Hello(env mango.Env) (mango.Status, mango.Headers, mango.Body) { // to add a session attribute just add it to the map env.Session()["new_session_attribute"] = "Never Gonna Give You Up" // To remove a session attribute delete it from the map env.Session()["old_session_attribute"] = nil, false return 200, mango.Headers{}, mango.Body("Hello World!") }
func Hello(env mango.Env) (mango.Status, mango.Headers, mango.Body) { env.Logger().Println("Got a", env.Request().Method, "request for", env.Request().RawURL) response, err := http.Get("http://www.weddinggalleryweb.com/") if err != nil { env.Logger().Printf("%s", err) os.Exit(1) } defer response.Body.Close() contents, err := ioutil.ReadAll(response.Body) if err != nil { env.Logger().Printf("%s", err) os.Exit(1) } return 200, mango.Headers{}, mango.Body(contents) }
func Cats(cat_images []string) mango.Middleware { // Initial setup stuff here // Done on application setup // Initialize our regex for finding image links regex := regexp.MustCompile("[^\"']+(.jpg|.png|.gif)") // This is our middleware's request handler return func(env mango.Env, app mango.App) (mango.Status, mango.Headers, mango.Body) { // Call the upstream application status, headers, body := app(env) // Pick a random cat image image_url := cat_images[rand.Int()%len(cat_images)] // Substitute in our cat picture body = mango.Body(regex.ReplaceAllString(string(body), image_url)) // Send the modified response onwards return status, headers, body } }
func Hello(env mango.Env) (mango.Status, mango.Headers, mango.Body) { env.Logger().Println("Got a", env.Request().Method, "request for", env.Request().RequestURI) return 200, mango.Headers{}, mango.Body("Hello Waold!") }
func Hello(env mango.Env) (mango.Status, mango.Headers, mango.Body) { return 200, mango.Headers{}, mango.Body("Hello World!") }
// Our default handler func Hello(env mango.Env) (mango.Status, mango.Headers, mango.Body) { //Return 500 to trigger the silence return 500, mango.Headers{}, mango.Body("Hello World!") }
func Index(env mango.Env) (mango.Status, mango.Headers, mango.Body) { env.Logger().Println("Got a", env.Request().Method, "request") return 200, mango.Headers{}, mango.Body("Index here. untested :P") }
func GetToken(env mango.Env) (mango.Status, mango.Headers, mango.Body) { return 200, mango.Headers{}, mango.Body("1234567890") }
// Our handler for /goodbye func Goodbye(env mango.Env) (mango.Status, mango.Headers, mango.Body) { return 200, mango.Headers{}, mango.Body("Goodbye World!") }