示例#1
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)
	}
}
//  traffic
func trafficHandler(w traffic.ResponseWriter, r *traffic.Request) {
	if sleepTime > 0 {
		time.Sleep(sleepTimeDuration)
	}
	w.Write(message)
}
示例#3
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)
}