Skip to content

Commit

Permalink
Merge pull request #3 from vitalyliber/flags
Browse files Browse the repository at this point in the history
Flags
  • Loading branch information
vitalyliber authored Dec 17, 2018
2 parents 67ebb18 + 8f29027 commit e8988bc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
31 changes: 12 additions & 19 deletions main.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down

0 comments on commit e8988bc

Please sign in to comment.