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


Golang ResponseWriter.Render方法代碼示例

本文整理匯總了Golang中github.com/pilu/traffic.ResponseWriter.Render方法的典型用法代碼示例。如果您正苦於以下問題:Golang ResponseWriter.Render方法的具體用法?Golang ResponseWriter.Render怎麽用?Golang ResponseWriter.Render使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/pilu/traffic.ResponseWriter的用法示例。


在下文中一共展示了ResponseWriter.Render方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: RequireValidImageParameters

func RequireValidImageParameters(w traffic.ResponseWriter, r *traffic.Request) {

	width, err := strconv.Atoi(r.Param("width"))
	if err != nil {
		w.WriteHeader(http.StatusNotFound)
		return
	}

	height, err := strconv.Atoi(r.Param("height"))
	if err != nil {
		height = width
	}

	if (width <= 2560 && width > 0) && (height <= 2560 && height > 0) {

		w.SetVar("width", width)
		w.SetVar("height", height)

		// log latest greatest creation
		if err := ioutil.WriteFile(filepath.Join(cache_folder, "/latest"), []byte(fmt.Sprintf("%d/%d", width, height)), 0644); err != nil {
			// panic is trapped by Traffic and show us a nice stack trace in the browser
			// a proper error handling should be provided, but in this simple example
			// it's used to remind you to always check for errors
			panic(err)
		}

	} else {
		// bad request
		w.WriteHeader(http.StatusBadRequest)
		w.Render("400")
	}

}
開發者ID:jmptrader,項目名稱:purrraceholder,代碼行數:33,代碼來源:image_handler.go

示例2: RootHandler

func RootHandler(w traffic.ResponseWriter, r *traffic.Request) {
	last_image_generated, err := ioutil.ReadFile("cache/latest")

	if err != nil {
		responseData := &ResponseData{string(last_image_generated)}
		w.Render("index", responseData)
	}
}
開發者ID:jmptrader,項目名稱:purrraceholder,代碼行數:8,代碼來源:root_handler.go

示例3: pageHandler

func pageHandler(w traffic.ResponseWriter, r *traffic.Request) {
	pagePath := r.Param("page_path")

	responseData := &ResponseData{
		PagePath: pagePath,
	}

	w.Render("index", responseData)
}
開發者ID:jmptrader,項目名稱:traffic,代碼行數:9,代碼來源:main.go

示例4: aboutHandler

func aboutHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.Render("about")
}
開發者ID:jmptrader,項目名稱:traffic,代碼行數:3,代碼來源:main.go

示例5: indexHandler

func indexHandler(w traffic.ResponseWriter, r *traffic.Request) {
	responseData := &ResponseData{"hello world"}
	w.Render("index", responseData)
}
開發者ID:jmptrader,項目名稱:traffic,代碼行數:4,代碼來源:main.go

示例6: RootHandler

func RootHandler(w traffic.ResponseWriter, r *traffic.Request) {
	responseData := &ResponseData{"Hello World"}
	w.Render("index", responseData)
}
開發者ID:jmptrader,項目名稱:traffic,代碼行數:4,代碼來源:root_handler.go

示例7: NotFoundHandler

func NotFoundHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.Render("404")
}
開發者ID:jmptrader,項目名稱:purrraceholder,代碼行數:3,代碼來源:notfound_handler.go

示例8: rootHandler

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

示例9: thirdPartyHandler

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

示例10: facetimeHandler

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


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