hwt/cmd/hwtc/main.go

44 lines
836 B
Go
Raw Normal View History

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"
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-21 20:12:05 -08:00
for i := 0; ; i++ {
2018-01-21 20:18:28 -08:00
resp, err := c.Hello(ctx, &pb.HelloReq{Subject: strings.Join(os.Args[2:], " ")})
2018-01-21 20:12:05 -08:00
if err != nil {
fmt.Fprintf(os.Stderr, "hello: %#v\n", err)
os.Exit(1)
}
fmt.Printf("0x%08x: %#v\n", i, resp)
2018-01-16 20:57:04 -08:00
}
}