Пример #1
0
func RequireValidImageParameters(w traffic.ResponseWriter, r *traffic.Request) {

	width, err := strconv.Atoi(r.Param("width"))
	if err != nil {
		w.WriteHeader(http.StatusNotFound)
		return
	}

	height, err := strconv.Atoi(r.Param("height"))
	if err != nil {
		height = width
	}

	if (width <= 2560 && width > 0) && (height <= 2560 && height > 0) {

		w.SetVar("width", width)
		w.SetVar("height", height)

		// log latest greatest creation
		if err := ioutil.WriteFile(filepath.Join(cache_folder, "/latest"), []byte(fmt.Sprintf("%d/%d", width, height)), 0644); err != nil {
			// panic is trapped by Traffic and show us a nice stack trace in the browser
			// a proper error handling should be provided, but in this simple example
			// it's used to remind you to always check for errors
			panic(err)
		}

	} else {
		// bad request
		w.WriteHeader(http.StatusBadRequest)
		w.Render("400")
	}

}
Пример #2
0
func RootHandler(w traffic.ResponseWriter, r *traffic.Request) {
	last_image_generated, err := ioutil.ReadFile("cache/latest")

	if err != nil {
		responseData := &ResponseData{string(last_image_generated)}
		w.Render("index", responseData)
	}
}
Пример #3
0
func pageHandler(w traffic.ResponseWriter, r *traffic.Request) {
	pagePath := r.Param("page_path")

	responseData := &ResponseData{
		PagePath: pagePath,
	}

	w.Render("index", responseData)
}
Пример #4
0
func aboutHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.Render("about")
}
Пример #5
0
func indexHandler(w traffic.ResponseWriter, r *traffic.Request) {
	responseData := &ResponseData{"hello world"}
	w.Render("index", responseData)
}
Пример #6
0
func RootHandler(w traffic.ResponseWriter, r *traffic.Request) {
	responseData := &ResponseData{"Hello World"}
	w.Render("index", responseData)
}
Пример #7
0
func NotFoundHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.Render("404")
}
Пример #8
0
func rootHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.Render("index", w.GetVar("phone"))
}
Пример #9
0
func thirdPartyHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.Render("third_party")
}
Пример #10
0
func facetimeHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.Render("facetime", w.GetVar("facetime"))
}