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")) }
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") } } }
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") }
// 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 }
func rootHandler(w traffic.ResponseWriter, r *traffic.Request) { traffic.Logger().Print("Hello") w.WriteText("Hello World\n") }
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")) }
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")) }
func rootHandler(w traffic.ResponseWriter, r *traffic.Request) { w.WriteText("Hello World\n") }
func customNotFoundHandler(w traffic.ResponseWriter, r *traffic.Request) { w.WriteHeader(http.StatusNotFound) w.WriteText("Page not found: %s\n", r.URL.Path) }
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) }
func checkPrivatePageApiKey(w traffic.ResponseWriter, r *traffic.Request) { if r.Param("private_api_key") != "bar" { w.WriteHeader(http.StatusUnauthorized) w.WriteText("Not authorized\n") } }
func checkApiKey(w traffic.ResponseWriter, r *traffic.Request) { if r.Param("api_key") != "foo" { w.WriteHeader(http.StatusUnauthorized) w.WriteText("Not authorized\n") } }
func privatePageHandler(w traffic.ResponseWriter, r *traffic.Request) { w.WriteText("Hello Private Page\n") }
func serverSideHandler(w traffic.ResponseWriter, r *traffic.Request) { w.WriteText("Resource not available\n") }