From 689339a0b58a85289236b0ca8268166e28710f3d Mon Sep 17 00:00:00 2001 From: vitalyliber Date: Tue, 18 Dec 2018 01:40:01 +0300 Subject: [PATCH 1/3] flags were added --- README.md | 9 ++------- main.go | 29 ++++++++++------------------- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 79dc6e6..94daf39 100644 --- a/README.md +++ b/README.md @@ -19,14 +19,9 @@ curl -L https://github.com/vitalyliber/gostorm/releases/download/v.1.0.1/gostorm sudo chmod a+x /usr/local/bin/gostorm ``` -- Run and paste url: +- Run with flags: ```bash -Enter site url: https://example.com -``` -- Enter number of streams: - -```bash -Enter number of streams: 500 +gostorm -url=https://some-url.ru -streams=500 ``` - Check the site accessible diff --git a/main.go b/main.go index 0652e68..3c7c4aa 100644 --- a/main.go +++ b/main.go @@ -1,37 +1,28 @@ package main import ( - "fmt" - "net/http" - "bufio" + "flag" "log" - "os" - "strconv" - "strings" + "net/http" ) 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") 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) + storm(*urlString) } func storm(url string) { From c3250ae36d37d037aca27e3167dd5cf92986bcba Mon Sep 17 00:00:00 2001 From: vitalyliber Date: Tue, 18 Dec 2018 01:59:11 +0300 Subject: [PATCH 2/3] flag timeout was added --- README.md | 22 ++++++++++++++++++++-- main.go | 4 +++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 94daf39..7897e35 100644 --- a/README.md +++ b/README.md @@ -14,18 +14,36 @@ sudo chmod a+x /usr/local/bin/gostorm - Download and install to Linux -``` +```bash curl -L https://github.com/vitalyliber/gostorm/releases/download/v.1.0.1/gostorm_linux -o /usr/local/bin/gostorm sudo chmod a+x /usr/local/bin/gostorm ``` - Run with flags: ```bash -gostorm -url=https://some-url.ru -streams=500 +gostorm -url=https://some-url.ru -streams=500 -timeout=1 ``` - Check the site accessible +## Flags + +```bash +gostorm -h +``` + +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 Linux diff --git a/main.go b/main.go index 3c7c4aa..1839e0f 100644 --- a/main.go +++ b/main.go @@ -4,11 +4,13 @@ import ( "flag" "log" "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() { flag.Parse() @@ -22,7 +24,7 @@ func main() { sum += 1 } - storm(*urlString) + time.Sleep(time.Duration(*timeout) * time.Minute) } func storm(url string) { From 8f29027557f2073e9c40374b365b34d6337fd1fb Mon Sep 17 00:00:00 2001 From: vitalyliber Date: Tue, 18 Dec 2018 02:02:09 +0300 Subject: [PATCH 3/3] fixed --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7897e35..b334bc9 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ 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 ``` @@ -15,7 +15,7 @@ sudo chmod a+x /usr/local/bin/gostorm ```bash -curl -L https://github.com/vitalyliber/gostorm/releases/download/v.1.0.1/gostorm_linux -o /usr/local/bin/gostorm +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 ```