示例#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
文件: cats.go 项目: victorcoder/mango
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
文件: vigia.go 项目: aleksclark/vigia
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
文件: logger.go 项目: qrush/higo
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!")
}