func main() { flag.UintVar(&concurrency, "c", 10, "number of concurrent requests") flag.UintVar(&requests, "n", 1000, "number of total requests to make") flag.UintVar(&timeout, "t", 15, "request timeout in seconds") flag.StringVar(®ion, "r", "us-east-1", "AWS regions to run in") flag.Parse() if len(flag.Args()) < 1 { fmt.Println("You must specify a URL as a last argument") os.Exit(1) } url = flag.Args()[0] test, testerr := goad.NewTest(&goad.TestConfig{ URL: url, Concurrency: concurrency, TotalRequests: requests, RequestTimeout: time.Duration(timeout) * time.Second, Region: region, }) if testerr != nil { fmt.Println(testerr) os.Exit(1) } var finalResult queue.RegionsAggData defer printSummary(&finalResult) sigChan := make(chan os.Signal, 1) signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) // but interrupts from kbd are blocked by termbox start(test, &finalResult, sigChan) }
func serveResults(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/goad" { http.Error(w, "Not found", 404) return } if r.Method != "GET" { http.Error(w, "Method not allowed", 405) return } w.Header().Set("Content-Type", "application/json; charset=utf-8") url := r.URL.Query().Get("url") if len(url) == 0 { http.Error(w, "Missing URL", 400) return } // Commented out param handling, we have hard coded limits for the website testing // // concurrencyStr := r.URL.Query().Get("c") // concurrency, cerr := strconv.Atoi(concurrencyStr) // if cerr != nil { // http.Error(w, "Invalid concurrency", 400) // return // } // // totStr := r.URL.Query().Get("tot") // tot, toterr := strconv.Atoi(totStr) // if toterr != nil { // http.Error(w, "Invalid total", 400) // return // } // // timeoutStr := r.URL.Query().Get("timeout") // timeout, timeouterr := strconv.Atoi(timeoutStr) // if timeouterr != nil { // http.Error(w, "Invalid timeout", 400) // return // } c, err := upgrader.Upgrade(w, r, nil) if err != nil { log.Print("Websocket upgrade:", err) return } defer c.Close() config := goad.TestConfig{ url, 5, 1000, time.Duration(7), "us-east-1", } test, testerr := goad.NewTest(&config) if testerr != nil { fmt.Println(testerr) return } resultChan := test.Start() for result := range resultChan { message, jsonerr := jsonFromRegionsAggData(result) if jsonerr != nil { log.Println(jsonerr) break } go readLoop(c) err = c.WriteMessage(websocket.TextMessage, []byte(message)) if err != nil { log.Println("write:", err) break } } }