1
0
Fork 0
This commit is contained in:
Atridad Lahiji 2024-01-14 16:13:45 -07:00
commit 2846824c1a
No known key found for this signature in database
4 changed files with 55 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
loadr

8
README.md Normal file
View file

@ -0,0 +1,8 @@
# Loadr
1. Run go run main.go <requests/second> <url>
2. ???
3. Profit
Example:
`go run main.go -rate=100 -url="https://google.com"`

3
go.mod Normal file
View file

@ -0,0 +1,3 @@
module loadr
go 1.21.6

43
main.go Normal file
View file

@ -0,0 +1,43 @@
package main
import (
"flag"
"fmt"
"net/http"
"sync/atomic"
"time"
)
var client = &http.Client{}
func makeGetRequest(url string) {
_, err := client.Get(url)
if err != nil {
fmt.Println("Error making GET request:", err)
return
}
fmt.Println("Request Sent")
}
func main() {
// Define command-line flags
requestsPerSecond := flag.Float64("rate", 10, "Number of requests per second")
url := flag.String("url", "https://example.com", "The URL to make requests to")
// Parse the flags
flag.Parse()
rateLimit := time.Second / time.Duration(*requestsPerSecond)
ticker := time.NewTicker(rateLimit)
defer ticker.Stop()
var requestCount int32 = 0
for range ticker.C {
go func(u string) {
makeGetRequest(u)
count := atomic.AddInt32(&requestCount, 1)
fmt.Printf("Number of requests: %d\n", count)
}(*url)
}
}