diff --git a/README.md b/README.md index 79dc6e6..b334bc9 100644 --- a/README.md +++ b/README.md @@ -7,29 +7,42 @@ Minimalistic performance and load testing tool written in Go. - Download and install to MacOS ``` -curl -L https://github.com/vitalyliber/gostorm/releases/download/v.1.0.1/gostorm_macos -o /usr/local/bin/gostorm +curl -L https://github.com/vitalyliber/gostorm/releases/download/v.1.0.2/gostorm_macos -o /usr/local/bin/gostorm sudo chmod a+x /usr/local/bin/gostorm ``` - Download and install to Linux -``` -curl -L https://github.com/vitalyliber/gostorm/releases/download/v.1.0.1/gostorm_linux -o /usr/local/bin/gostorm +```bash +curl -L https://github.com/vitalyliber/gostorm/releases/download/v.1.0.2/gostorm_linux -o /usr/local/bin/gostorm sudo chmod a+x /usr/local/bin/gostorm ``` -- Run and paste url: +- Run with flags: ```bash -Enter site url: https://example.com +gostorm -url=https://some-url.ru -streams=500 -timeout=1 ``` -- Enter number of streams: + +- Check the site accessible + +## Flags ```bash -Enter number of streams: 500 +gostorm -h ``` -- Check the site accessible +Output: +```bash +Usage of ./main: + -streams int + a number of streams (default 42) + -timeout int + timeout in minutes for working of program (default 1) + -url string + a site url (default "https://some-url.com") + +``` ## Build for your platform diff --git a/main.go b/main.go index 0652e68..1839e0f 100644 --- a/main.go +++ b/main.go @@ -1,37 +1,30 @@ package main import ( - "fmt" - "net/http" - "bufio" + "flag" "log" - "os" - "strconv" - "strings" + "net/http" + "time" ) var counter = 0 +var urlString = flag.String("url", "https://some-url.com", "a site url") +var streams = flag.Int("streams", 42, "a number of streams") +var timeout = flag.Int("timeout", 1, "timeout in minutes for working of program") func main() { - reader := bufio.NewReader(os.Stdin) - fmt.Print("Enter site url: ") - urlString, _ := reader.ReadString('\n') - urlString = strings.TrimSuffix(urlString, "\n") - - fmt.Print("Enter number of streams: ") - streamsString, _ := reader.ReadString('\n') - streamsString = strings.TrimSuffix(streamsString, "\n") - streams, _ := strconv.Atoi(streamsString) - log.Println("Streams:", streams) + flag.Parse() + log.Println("Url:", *urlString) + log.Println("Streams number:", *streams) sum := 1 - for sum < streams { - go storm(urlString) + for sum < *streams { + go storm(*urlString) log.Println("Goroutine was created with number:", sum) sum += 1 } - storm(urlString) + time.Sleep(time.Duration(*timeout) * time.Minute) } func storm(url string) {