当前位置: 首页>>代码示例>>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;未经允许,请勿转载。