Exemple #1
0
func rootHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.WriteText("%s<br />", w.GetVar("foo"))

	// run with TRAFFIC_ENV=production to get the "bar" value
	// from the production section of the config file
	w.WriteText("%s<br />", w.GetVar("bar"))
}
Exemple #2
0
func rootHandler(w traffic.ResponseWriter, r *traffic.Request) {
	logger := w.GetVar("chromelogger").(*chromelogger.Logger)

	logger.Log("Hello")
	logger.Log(map[string]string{
		"foo": "bar",
	})

	w.WriteText("Hello, check your Chrome console after activating the Chrome Logger extension.\n")
}
func ImageHandler(w traffic.ResponseWriter, r *traffic.Request) {
	// output the image with the correct content-type
	w.Header().Set("Content-Type", "image/jpeg")

	// at this point we can safely assume that the image file already exists
	if image_data, err := ioutil.ReadFile(w.GetVar("filename").(string)); err != nil {
		panic(err)
	} else {
		w.Write(image_data)
	}
}
func GenerateImageCache(w traffic.ResponseWriter, r *traffic.Request) {

	if !exists(cache_folder) {
		if err := os.Mkdir(cache_folder, 0644); err != nil {
			panic(err)
		}
	}

	filename := fmt.Sprintf("%s/%dx%d.jpg", cache_folder, w.GetVar("width"), w.GetVar("height"))
	w.SetVar("filename", filename)

	if !exists(filename) {
		// file does not exists, generate a cached version
		width := w.GetVar("width").(int)
		height := w.GetVar("height").(int)

		src_image := loadImageFromFile(image_file)
		pattern := resizeImage(src_image, width, height)

		var dst_image image.Image
		if width > height {
			dst_image = tileImageHorizontally(pattern, width, height)
		} else {
			dst_image = tileImageVertically(pattern, width, height)
		}

		saveImageToFile(filename, dst_image)
	}
}
Exemple #5
0
func root(w traffic.ResponseWriter, r *traffic.Request) {
	w.WriteText("Router var foo: %v.\n", w.GetVar("foo"))
	w.WriteText("Middleware var ping: %v\n", w.GetVar("ping"))
}
func piluTrafficCompositeHandler(rw traffic.ResponseWriter, r *traffic.Request) {
	fieldVal := rw.GetVar("field").(string)
	fmt.Fprintf(rw, fieldVal)
}
Exemple #7
0
func rootHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.Render("index", w.GetVar("phone"))
}
Exemple #8
0
func facetimeHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.Render("facetime", w.GetVar("facetime"))
}
Exemple #9
0
func addLocationHeader(w traffic.ResponseWriter, r *traffic.Request) {
	t := fmt.Sprintf("tel://%s", w.GetVar("phone"))
	w.Header().Add("Location", t)
	w.WriteHeader(http.StatusTemporaryRedirect)
}