Created
January 14, 2024 15:10
-
-
Save sgf-dma/1bc20722e57ebfc7ee8629b2a877209d to your computer and use it in GitHub Desktop.
race tester
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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