innit
This commit is contained in:
commit
2846824c1a
4 changed files with 55 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
loadr
|
8
README.md
Normal file
8
README.md
Normal 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
3
go.mod
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
module loadr
|
||||||
|
|
||||||
|
go 1.21.6
|
43
main.go
Normal file
43
main.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue