Beispiel #1
0
func rootHandler(w traffic.ResponseWriter, r *traffic.Request) {
	response := map[string]string{
		"version": VERSION,
	}
	w.Header().Set("Content-Type", "application/json")
	json.NewEncoder(w).Encode(response)
}
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)
	}
}
Beispiel #3
0
func codesHandler(w traffic.ResponseWriter, r *traffic.Request) {
	code := r.Param("code")
	url := fmt.Sprintf("%s%s", baseUrl, code)

	grid, err := qrencode.Encode(url, qrencode.ECLevelQ)
	if err != nil {
		panic(err)
	}

	w.Header().Set("Content-Type", "image/png")
	png.Encode(w, grid.Image(8))
}
Beispiel #4
0
func SetDefaultHeaders(w traffic.ResponseWriter, r *traffic.Request) {
	w.Header().Set("Cerebellum-Version", VERSION)
	w.Header().Set("Content-Type", "application/json; charset=utf-8")
}
func PoweredByHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.Header().Set("X-Powered-By", "Grumpy cat")
}
Beispiel #6
0
func addTimeHeader(w traffic.ResponseWriter, r *traffic.Request) {
	t := fmt.Sprintf("%s", time.Now())
	w.Header().Add("X-APP-TIME", t)
}
Beispiel #7
0
func addAppNameHeader(w traffic.ResponseWriter, r *traffic.Request) {
	w.Header().Add("X-APP-NAME", "My App")
}
Beispiel #8
0
func sendJpeg(w traffic.ResponseWriter, data []byte) {

	w.Header().Set("Content-Type", "image/jpeg")
	w.Header().Set("Content-Length", strconv.Itoa(len(data)))
	w.Write(data)
}
Beispiel #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)
}