blob: 60023ba383561308278d0049d7f4542b04a3b488 [file] [log] [blame]
package main
import (
"flag"
"log"
"golang.org/x/net/context"
"google.golang.org/grpc"
pb "v.io/x/ref/examples/grpc-fortune/proto"
"v.io/x/ref/examples/grpc-fortune/vgrpc"
)
const (
address = "localhost:50053"
defaultName = "world"
)
func main() {
get := flag.Bool("g", false, "Whether to make a get request.")
add := flag.String("a", "", "Add a fortune.")
has := flag.String("h", "", "Check whether a fortune is present.")
flag.Parse()
// Set up a connection to the server.
conn, err := grpc.Dial(address, grpc.WithTransportCredentials(&vgrpc.VanadiumCred{}))
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer conn.Close()
c := pb.NewFortuneClient(conn)
if *get {
log.Printf("Calling Get now.")
r, err := c.Get(context.Background(), &pb.FortuneGetRequest{})
if err != nil {
log.Fatalf("could not get: %v", err)
}
log.Printf("Fortune: %s", r.Fortune)
}
if *add != "" {
_, err := c.Add(context.Background(), &pb.FortuneAddRequest{Fortune: *add})
if err != nil {
log.Fatalf("could not add: %v", err)
}
log.Printf("Added: %s", *add)
}
if *has != "" {
r, err := c.Has(context.Background(), &pb.FortuneHasRequest{Fortune: *has})
if err != nil {
log.Fatalf("could not call has: %v", err)
}
if r.Has {
log.Printf("Fortune found.")
} else {
log.Printf("Fortune not found.")
}
}
}