func Search(c projects.ProjectsServiceClient, ctx context.Context, terms string) { req := &projects.ProjectsSearchRequest{SearchTerms: terms} log.Printf("Searching for '%s'", terms) resp, err := c.Search(ctx, req) if err != nil { log.Fatalf("could not search: %v", err) } log.Printf("Found %d of %d possible", resp.Results, resp.Known) pp.Print(resp.Projects) }
func Create(c projects.ProjectsServiceClient, ctx context.Context, id, name string) { uid := parseID(id) p := projects.Project{Id: uid, Name: name} created, err := c.Create(ctx, &p) if grpc.Code(err) == codes.AlreadyExists { log.Printf("that ID is taken") return } else if err != nil { log.Fatalf("could not create: %v", err) return } pp.Print(created) }
func Find(c projects.ProjectsServiceClient, ctx context.Context, id string) { uid := parseID(id) log.Printf("Finding '%d'", uid) proj, err := c.Get(ctx, &projects.ProjectRequest{Id: uid}) if grpc.Code(err) == codes.NotFound { log.Printf("the project you wanted does not exist") return } else if err != nil { log.Fatalf("could not find: %v", err) return } pp.Print(proj) }
func SlowSearch(c projects.ProjectsServiceClient, ctx context.Context, terms string) { req := &projects.ProjectsSearchRequest{SearchTerms: terms} log.Printf("Slow Searching for '%s'", terms) stream, err := c.SlowSearch(ctx, req) if err != nil { log.Fatalf("could not slow search: %v", err) } for { prj, err := stream.Recv() if err == io.EOF { break } if err != nil { log.Fatalf("receiving slow search result: %v", err) } pp.Print(prj) } }