本文整理汇总了Golang中github.com/pilu/traffic.ResponseWriter.Header方法的典型用法代码示例。如果您正苦于以下问题:Golang ResponseWriter.Header方法的具体用法?Golang ResponseWriter.Header怎么用?Golang ResponseWriter.Header使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pilu/traffic.ResponseWriter
的用法示例。
在下文中一共展示了ResponseWriter.Header方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: rootHandler
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: 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)
}
}
示例3: codesHandler
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: SetDefaultHeaders
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: PoweredByHandler
func PoweredByHandler(w traffic.ResponseWriter, r *traffic.Request) {
w.Header().Set("X-Powered-By", "Grumpy cat")
}
示例6: addTimeHeader
func addTimeHeader(w traffic.ResponseWriter, r *traffic.Request) {
t := fmt.Sprintf("%s", time.Now())
w.Header().Add("X-APP-TIME", t)
}
示例7: addAppNameHeader
func addAppNameHeader(w traffic.ResponseWriter, r *traffic.Request) {
w.Header().Add("X-APP-NAME", "My App")
}
示例8: 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)
}
示例9: addLocationHeader
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)
}