本文整理汇总了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"))
}
示例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")
}
}
}
示例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")
}
示例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
}
示例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"))
}
示例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"))
}
示例7: customNotFoundHandler
func customNotFoundHandler(w traffic.ResponseWriter, r *traffic.Request) {
w.WriteHeader(http.StatusNotFound)
w.WriteText("Page not found: %s\n", r.URL.Path)
}
示例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)
}
示例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")
}
}
示例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")
}
}
示例11: privatePageHandler
func privatePageHandler(w traffic.ResponseWriter, r *traffic.Request) {
w.WriteText("Hello Private Page\n")
}
示例12: serverSideHandler
func serverSideHandler(w traffic.ResponseWriter, r *traffic.Request) {
w.WriteText("Resource not available\n")
}