當前位置: 首頁>>代碼示例>>Golang>>正文


Golang ResponseWriter.GetVar方法代碼示例

本文整理匯總了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"))
}
開發者ID:jmptrader,項目名稱:traffic,代碼行數:7,代碼來源:main.go

示例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")
}
開發者ID:pilu,項目名稱:traffic-chromelogger,代碼行數:10,代碼來源:main.go

示例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)
	}
}
開發者ID:jmptrader,項目名稱:purrraceholder,代碼行數:11,代碼來源:image_handler.go

示例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)
	}
}
開發者ID:jmptrader,項目名稱:purrraceholder,代碼行數:29,代碼來源:image_handler.go

示例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"))
}
開發者ID:jmptrader,項目名稱:traffic,代碼行數:4,代碼來源:main.go

示例6: piluTrafficCompositeHandler

func piluTrafficCompositeHandler(rw traffic.ResponseWriter, r *traffic.Request) {
	fieldVal := rw.GetVar("field").(string)
	fmt.Fprintf(rw, fieldVal)
}
開發者ID:rexk,項目名稱:golang-mux-benchmark,代碼行數:4,代碼來源:mux_bench_test.go

示例7: rootHandler

func rootHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.Render("index", w.GetVar("phone"))
}
開發者ID:karmatr0n,項目名稱:url-schemes,代碼行數:3,代碼來源:main.go

示例8: facetimeHandler

func facetimeHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.Render("facetime", w.GetVar("facetime"))
}
開發者ID:karmatr0n,項目名稱:url-schemes,代碼行數:3,代碼來源:main.go

示例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)
}
開發者ID:karmatr0n,項目名稱:url-schemes,代碼行數:5,代碼來源:main.go


注:本文中的github.com/pilu/traffic.ResponseWriter.GetVar方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。