Beispiel #1
0
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"))
}
Beispiel #2
0
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")
		}
	}
}
Beispiel #3
0
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")
}
Beispiel #4
0
// 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
}
Beispiel #5
0
func rootHandler(w traffic.ResponseWriter, r *traffic.Request) {
	traffic.Logger().Print("Hello")
	w.WriteText("Hello World\n")
}
Beispiel #6
0
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"))
}
Beispiel #7
0
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"))
}
Beispiel #8
0
func rootHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.WriteText("Hello World\n")
}
Beispiel #9
0
func customNotFoundHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.WriteHeader(http.StatusNotFound)
	w.WriteText("Page not found: %s\n", r.URL.Path)
}
Beispiel #10
0
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)
}
Beispiel #11
0
func checkPrivatePageApiKey(w traffic.ResponseWriter, r *traffic.Request) {
	if r.Param("private_api_key") != "bar" {
		w.WriteHeader(http.StatusUnauthorized)
		w.WriteText("Not authorized\n")
	}
}
Beispiel #12
0
func checkApiKey(w traffic.ResponseWriter, r *traffic.Request) {
	if r.Param("api_key") != "foo" {
		w.WriteHeader(http.StatusUnauthorized)
		w.WriteText("Not authorized\n")
	}
}
Beispiel #13
0
func privatePageHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.WriteText("Hello Private Page\n")
}
Beispiel #14
0
func serverSideHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.WriteText("Resource not available\n")
}