Skip to content

Instantly share code, notes, and snippets.

@sgf-dma
Created January 14, 2024 15:10
Show Gist options
  • Save sgf-dma/1bc20722e57ebfc7ee8629b2a877209d to your computer and use it in GitHub Desktop.
Save sgf-dma/1bc20722e57ebfc7ee8629b2a877209d to your computer and use it in GitHub Desktop.
race tester
package main
import (
"fmt"
"sync"
"net/http"
"bytes"
)
func worker(i int, ch <-chan interface{}) {
fmt.Printf("[%v]: Ready\n", i)
<-ch
fmt.Printf("[%v]: Started\n", i)
bs := bytes.NewBufferString("http://ayaginkdkzmu.net/keu3mjdqmlun/jucsjdybso6s0")
resp, err := http.Post("http://localhost:8080/", "text/plain; charset=utf-8", bs)
if err != nil {
panic(3)
}
defer resp.Body.Close()
var rs bytes.Buffer
rs.ReadFrom(resp.Body)
fmt.Printf("[%v]: Done with %v\n", i, rs.String())
}
func main() {
ch := make(chan interface{})
var wg sync.WaitGroup
for i := 0; i < 10; i++ {
wg.Add(1)
go func (i int) {
defer wg.Done()
worker(i, ch)
}(i)
}
close(ch)
wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment