2018-01-16 20:57:04 -08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
2018-01-21 20:18:28 -08:00
|
|
|
"github.com/twitchtv/twirp"
|
|
|
|
|
|
|
|
"mcquay.me/hwt"
|
2018-01-20 08:38:58 -08:00
|
|
|
pb "mcquay.me/hwt/rpc/hwt"
|
2018-01-16 20:57:04 -08:00
|
|
|
)
|
|
|
|
|
2018-01-20 08:49:02 -08:00
|
|
|
const usage = "hwtc <server address> [subject]"
|
2018-01-16 20:57:04 -08:00
|
|
|
|
|
|
|
func main() {
|
2018-01-20 08:49:02 -08:00
|
|
|
if len(os.Args) < 3 {
|
2018-01-16 20:57:04 -08:00
|
|
|
fmt.Fprintf(os.Stderr, "%v\n", usage)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2018-01-20 08:49:02 -08:00
|
|
|
c := pb.NewHelloWorldProtobufClient(fmt.Sprintf("http://%s", os.Args[1]), &http.Client{})
|
2018-01-16 20:57:04 -08:00
|
|
|
|
2018-01-21 20:18:28 -08:00
|
|
|
h := http.Header{}
|
|
|
|
h.Set("sm-auth", hwt.PSK)
|
|
|
|
ctx := context.Background()
|
|
|
|
ctx, err := twirp.WithHTTPRequestHeaders(ctx, h)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "setting twirp headers: %v\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2018-01-26 17:15:13 -08:00
|
|
|
s := make(chan bool, 10)
|
2018-01-21 20:12:05 -08:00
|
|
|
for i := 0; ; i++ {
|
2018-01-26 17:15:13 -08:00
|
|
|
s <- true
|
|
|
|
go func(j int) {
|
|
|
|
resp, err := c.Hello(ctx, &pb.HelloReq{Subject: strings.Join(os.Args[2:], " ")})
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "hello: %#v\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
fmt.Printf("0x%08x: %#v\n", j, resp)
|
|
|
|
<-s
|
|
|
|
}(i)
|
2018-01-16 20:57:04 -08:00
|
|
|
}
|
|
|
|
}
|