本文整理匯總了Golang中github.com/pilu/traffic.ResponseWriter.Write方法的典型用法代碼示例。如果您正苦於以下問題:Golang ResponseWriter.Write方法的具體用法?Golang ResponseWriter.Write怎麽用?Golang ResponseWriter.Write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pilu/traffic.ResponseWriter
的用法示例。
在下文中一共展示了ResponseWriter.Write方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ImageHandler
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)
}
}
示例2: trafficHandler
// traffic
func trafficHandler(w traffic.ResponseWriter, r *traffic.Request) {
if sleepTime > 0 {
time.Sleep(sleepTimeDuration)
}
w.Write(message)
}
示例3: sendJpeg
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)
}