haberdasher-twirp/cmd/client/main.go

36 lines
692 B
Go
Raw Normal View History

2021-07-26 14:00:25 +00:00
package main
import (
"context"
"fmt"
"net/http"
"os"
"haberdasher-twirp/haberdasher"
)
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: 12})
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)
}
}