commit 2846824c1acaba7ecb687109d8458fac46bd1a56 Author: atridadl Date: Sun Jan 14 16:13:45 2024 -0700 innit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6ace1d2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +loadr \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..305dced --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# Loadr + +1. Run go run main.go +2. ??? +3. Profit + +Example: +`go run main.go -rate=100 -url="https://google.com"` diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..8dbdf0b --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module loadr + +go 1.21.6 diff --git a/main.go b/main.go new file mode 100644 index 0000000..16b95a6 --- /dev/null +++ b/main.go @@ -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) + } +}