示例#1
0
文件: stickerl.go 项目: pilu/stickerl
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)
}
示例#2
0
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)
	}
}
示例#3
0
文件: stickerl.go 项目: pilu/stickerl
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))
}
示例#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")
}
示例#6
0
文件: main.go 项目: jmptrader/traffic
func addTimeHeader(w traffic.ResponseWriter, r *traffic.Request) {
	t := fmt.Sprintf("%s", time.Now())
	w.Header().Add("X-APP-TIME", t)
}
示例#7
0
文件: main.go 项目: jmptrader/traffic
func addAppNameHeader(w traffic.ResponseWriter, r *traffic.Request) {
	w.Header().Add("X-APP-NAME", "My App")
}
示例#8
0
文件: api.go 项目: jhyle/imgserver
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)
}
示例#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)
}