Пример #1
0
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!")
}
Пример #2
0
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)
}
Пример #3
0
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
	}
}
Пример #4
0
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!")
}
Пример #5
0
func Hello(env mango.Env) (mango.Status, mango.Headers, mango.Body) {
	return 200, mango.Headers{}, mango.Body("Hello World!")
}
Пример #6
0
// 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!")
}
Пример #7
0
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")
}
Пример #8
0
func GetToken(env mango.Env) (mango.Status, mango.Headers, mango.Body) {
	return 200, mango.Headers{}, mango.Body("1234567890")
}
Пример #9
0
// Our handler for /goodbye
func Goodbye(env mango.Env) (mango.Status, mango.Headers, mango.Body) {
	return 200, mango.Headers{}, mango.Body("Goodbye World!")
}