Esempio n. 1
0
func triangle(w http.ResponseWriter, r *http.Request) {
	t := time.Now()

	width, err := strconv.Atoi(r.FormValue("width"))
	height, err := strconv.Atoi(r.FormValue("height"))
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	if width <= 0 || height <= 0 {
		http.Error(w, "Size not valid", http.StatusBadRequest)
		return
	}
	if width > 5120 || height > 2880 {
		http.Error(w, "Maximum resolution via server is 5120x2880. Use the console client to generate larger images.", http.StatusBadRequest)
		return
	}

	h := w.Header()
	h.Set("Content-Type", "image/svg+xml")
	h.Set("Vary", "Accept-Encoding")
	h.Set("Cache-Control", "no-cache, no-store, must-revalidate")
	h.Set("Pragma", "no-cache")
	h.Set("Expires", "0")
	tessellated.Triangle(w, float64(width), float64(height))
	fmt.Printf("Triangle background of size %d, %d took %v\n", width, height, time.Since(t))
}
Esempio n. 2
0
func main() {
	flag.Parse()

	if -1 == port {
		var p Printer
		tessellated.Triangle(p, Width, Height)
		return
	}

	if 65535 < port || port < 0 {
		fmt.Println("Invalid Port!")
		return
	}

	http.HandleFunc("/", root)
	http.HandleFunc("/triangle.svg", triangle)
	err := http.ListenAndServe(fmt.Sprintf(":%d", port), nil)
	fmt.Println(err)
}