コード例 #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
ファイル: common_handlers.go プロジェクト: pilu/cerebellum
func SetDefaultHeaders(w traffic.ResponseWriter, r *traffic.Request) {
	w.Header().Set("Cerebellum-Version", VERSION)
	w.Header().Set("Content-Type", "application/json; charset=utf-8")
}
コード例 #5
0
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
ファイル: main.go プロジェクト: karmatr0n/url-schemes
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)
}