fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

1package grpc 2 3import ( 4 "context" 5 6 "google.golang.org/grpc/codes" 7 "google.golang.org/grpc/status" 8 9 "github.com/sourcegraph/zoekt" 10 v1 "github.com/sourcegraph/zoekt/grpc/v1" 11 "github.com/sourcegraph/zoekt/query" 12 "github.com/sourcegraph/zoekt/stream" 13) 14 15func NewServer(s zoekt.Streamer) *Server { 16 return &Server{ 17 streamer: s, 18 } 19} 20 21type Server struct { 22 v1.UnimplementedWebserverServiceServer 23 streamer zoekt.Streamer 24} 25 26func (s *Server) Search(ctx context.Context, req *v1.SearchRequest) (*v1.SearchResponse, error) { 27 q, err := query.QFromProto(req.GetQuery()) 28 if err != nil { 29 return nil, status.Error(codes.InvalidArgument, err.Error()) 30 } 31 32 res, err := s.streamer.Search(ctx, q, zoekt.SearchOptionsFromProto(req.GetOpts())) 33 if err != nil { 34 return nil, err 35 } 36 37 return res.ToProto(), nil 38} 39 40func (s *Server) StreamSearch(req *v1.SearchRequest, ss v1.WebserverService_StreamSearchServer) error { 41 q, err := query.QFromProto(req.GetQuery()) 42 if err != nil { 43 return status.Error(codes.InvalidArgument, err.Error()) 44 } 45 46 onMatch := stream.SenderFunc(func(res *zoekt.SearchResult) { 47 ss.Send(res.ToProto()) 48 }) 49 50 return s.streamer.StreamSearch(ss.Context(), q, zoekt.SearchOptionsFromProto(req.GetOpts()), onMatch) 51} 52 53func (s *Server) List(ctx context.Context, req *v1.ListRequest) (*v1.ListResponse, error) { 54 q, err := query.QFromProto(req.GetQuery()) 55 if err != nil { 56 return nil, status.Error(codes.InvalidArgument, err.Error()) 57 } 58 59 repoList, err := s.streamer.List(ctx, q, zoekt.ListOptionsFromProto(req.GetOpts())) 60 if err != nil { 61 return nil, err 62 } 63 64 return repoList.ToProto(), nil 65}