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


Golang ResponseWriter.WriteText方法代碼示例

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


在下文中一共展示了ResponseWriter.WriteText方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: CheckForDdosString

func CheckForDdosString(w traffic.ResponseWriter, r *traffic.Request) {
	for k, _ := range uriFragments {
		fmt.Printf("Searching for %s in %s", k, r.RequestURI)
		if strings.Contains(r.RequestURI, k) {
			fmt.Printf("Found %s", k)
			w.WriteHeader(http.StatusGatewayTimeout)
			w.WriteText("connection timed out")
		}
	}
}
開發者ID:dvwallin,項目名稱:goddos,代碼行數:10,代碼來源:goddos.go

示例3: 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

示例4: ServeHTTP

// If the request path is "/ping", it writes PONG in the response and returns without calling the next middleware
// Otherwise it sets the variable "PING" with PONG as value and calls the next  middleware.
// The next middleware and the final handler can get that variable with:
//   w.GetVar("ping")
func (c *PingMiddleware) ServeHTTP(w traffic.ResponseWriter, r *traffic.Request, next traffic.NextMiddlewareFunc) {
	if r.URL.Path == "/ping" {
		w.WriteText("pong\n")

		return
	}

	if nextMiddleware := next(); nextMiddleware != nil {
		w.SetVar("ping", "pong")
		nextMiddleware.ServeHTTP(w, r, next)
	}

	return
}
開發者ID:jmptrader,項目名稱:traffic,代碼行數:18,代碼來源:main.go

示例5: pageHandler

func pageHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.WriteText("Category ID: %s\n", r.Param("category_id"))
	w.WriteText("Page ID: %s\n", r.Param("id"))
}
開發者ID:jmptrader,項目名稱:traffic,代碼行數:4,代碼來源:main.go

示例6: 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

示例7: customNotFoundHandler

func customNotFoundHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.WriteHeader(http.StatusNotFound)
	w.WriteText("Page not found: %s\n", r.URL.Path)
}
開發者ID:jmptrader,項目名稱:traffic,代碼行數:4,代碼來源:main.go

示例8: errorHandler

func errorHandler(w traffic.ResponseWriter, r *traffic.Request, err interface{}) {
	w.WriteText("This is a custom error page <br />\n")
	w.WriteText("Recovered from `%v`", err)
}
開發者ID:jmptrader,項目名稱:traffic,代碼行數:4,代碼來源:main.go

示例9: checkPrivatePageApiKey

func checkPrivatePageApiKey(w traffic.ResponseWriter, r *traffic.Request) {
	if r.Param("private_api_key") != "bar" {
		w.WriteHeader(http.StatusUnauthorized)
		w.WriteText("Not authorized\n")
	}
}
開發者ID:jmptrader,項目名稱:traffic,代碼行數:6,代碼來源:main.go

示例10: checkApiKey

func checkApiKey(w traffic.ResponseWriter, r *traffic.Request) {
	if r.Param("api_key") != "foo" {
		w.WriteHeader(http.StatusUnauthorized)
		w.WriteText("Not authorized\n")
	}
}
開發者ID:jmptrader,項目名稱:traffic,代碼行數:6,代碼來源:main.go

示例11: privatePageHandler

func privatePageHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.WriteText("Hello Private Page\n")
}
開發者ID:jmptrader,項目名稱:traffic,代碼行數:3,代碼來源:main.go

示例12: serverSideHandler

func serverSideHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.WriteText("Resource not available\n")
}
開發者ID:karmatr0n,項目名稱:url-schemes,代碼行數:3,代碼來源:main.go


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