goLoad/main.go
2022-03-04 00:19:52 +01:00

49 lines
1.0 KiB
Go

package main
import (
"fmt"
"net/http"
"sync"
"time"
"github.com/rivo/tview"
)
func main() {
app := tview.NewApplication()
list := tview.NewList().
AddItem("List item 1", "Some explanatory text", 'a', webload).
AddItem("List item 2", "Some explanatory text", 'b', nil).
AddItem("List item 3", "Some explanatory text", 'c', nil).
AddItem("List item 4", "Some explanatory text", 'd', nil).
AddItem("Quit", "Press to exit", 'q', func() {
app.Stop()
})
if err := app.SetRoot(list, true).SetFocus(list).Run(); err != nil {
panic(err)
}
}
func webload() {
wg := sync.WaitGroup{}
wg.Add(1000)
for i := 0; i < 1000; i++ {
go webrequest(&wg)
}
wg.Done()
fmt.Println("Launched 100 Request")
}
func webrequest(wg *sync.WaitGroup) {
time.Sleep(time.Second)
protocol := "https://"
url := "heimdall.voser.cloud"
resp, err := http.Get(fmt.Sprintf("%s%s", protocol, url))
if err != nil {
fmt.Println(err)
} else {
fmt.Printf("Response status code: %d", resp.StatusCode)
}
defer resp.Body.Close()
}