本文整理匯總了Golang中github.com/pilu/traffic.ResponseWriter.GetVar方法的典型用法代碼示例。如果您正苦於以下問題:Golang ResponseWriter.GetVar方法的具體用法?Golang ResponseWriter.GetVar怎麽用?Golang ResponseWriter.GetVar使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pilu/traffic.ResponseWriter
的用法示例。
在下文中一共展示了ResponseWriter.GetVar方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: rootHandler
func rootHandler(w traffic.ResponseWriter, r *traffic.Request) {
w.WriteText("%s<br />", w.GetVar("foo"))
// run with TRAFFIC_ENV=production to get the "bar" value
// from the production section of the config file
w.WriteText("%s<br />", w.GetVar("bar"))
}
示例2: rootHandler
func rootHandler(w traffic.ResponseWriter, r *traffic.Request) {
logger := w.GetVar("chromelogger").(*chromelogger.Logger)
logger.Log("Hello")
logger.Log(map[string]string{
"foo": "bar",
})
w.WriteText("Hello, check your Chrome console after activating the Chrome Logger extension.\n")
}
示例3: 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)
}
}
示例4: GenerateImageCache
func GenerateImageCache(w traffic.ResponseWriter, r *traffic.Request) {
if !exists(cache_folder) {
if err := os.Mkdir(cache_folder, 0644); err != nil {
panic(err)
}
}
filename := fmt.Sprintf("%s/%dx%d.jpg", cache_folder, w.GetVar("width"), w.GetVar("height"))
w.SetVar("filename", filename)
if !exists(filename) {
// file does not exists, generate a cached version
width := w.GetVar("width").(int)
height := w.GetVar("height").(int)
src_image := loadImageFromFile(image_file)
pattern := resizeImage(src_image, width, height)
var dst_image image.Image
if width > height {
dst_image = tileImageHorizontally(pattern, width, height)
} else {
dst_image = tileImageVertically(pattern, width, height)
}
saveImageToFile(filename, dst_image)
}
}
示例5: root
func root(w traffic.ResponseWriter, r *traffic.Request) {
w.WriteText("Router var foo: %v.\n", w.GetVar("foo"))
w.WriteText("Middleware var ping: %v\n", w.GetVar("ping"))
}
示例6: piluTrafficCompositeHandler
func piluTrafficCompositeHandler(rw traffic.ResponseWriter, r *traffic.Request) {
fieldVal := rw.GetVar("field").(string)
fmt.Fprintf(rw, fieldVal)
}
示例7: rootHandler
func rootHandler(w traffic.ResponseWriter, r *traffic.Request) {
w.Render("index", w.GetVar("phone"))
}
示例8: facetimeHandler
func facetimeHandler(w traffic.ResponseWriter, r *traffic.Request) {
w.Render("facetime", w.GetVar("facetime"))
}
示例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)
}