package main import ( "context" "fmt" "math/rand" "net/http" "os" "haberdasher-twirp/haberdasher" ) const MaxSize = 12 func main() { var host string = "http://localhost:8080" if len(os.Args) > 1 { host = os.Args[1] } client := haberdasher.NewHaberdasherProtobufClient(host, &http.Client{}) hat, err := client.MakeHat(context.Background(), &haberdasher.Size{Inches: int32(rand.Intn(MaxSize))}) if err != nil { fmt.Printf("oh no: %v\n", err) os.Exit(1) } fmt.Printf("I have a nice new hat: %+v\n", hat) hats, err := client.ListHats(context.Background(), &haberdasher.HatQuery{Limit: 20}) if err != nil { fmt.Printf("oh no: %v\n", err) os.Exit(1) } for i, h := range hats.Hats { fmt.Printf("%d: %+v\n", i, h) } }