diff --git a/ProtoHandler/Handler.go b/ProtoHandler/Handler.go index 2ec02c1..67ab31d 100644 --- a/ProtoHandler/Handler.go +++ b/ProtoHandler/Handler.go @@ -18,26 +18,26 @@ func createConnection() *grpc.ClientConn{ logger.Fatal(err) } - defer conn.Close() - return conn } -func createRegistryClient() (proto.LpmRegistryClient, context.Context){ +func createRegistryClient(conn *grpc.ClientConn) (proto.LpmRegistryClient, context.Context, context.CancelFunc){ - lrc := proto.NewLpmRegistryClient(createConnection()) + lrc := proto.NewLpmRegistryClient(conn) ctx, cancel := context.WithTimeout(context.Background(), time.Second * 10) - defer cancel() - - return lrc, ctx + return lrc, ctx, cancel } func SearchPackages(platform string, architecture []string, query string) []PackageMetadata { - logger := Lotus.DetailedLogger("ProtoHandler", "sendSearchRequest") - client, ctx := createRegistryClient() + conn := createConnection() + defer conn.Close() + + client, ctx, cancel := createRegistryClient(conn) + defer cancel() + res, connErr := client.Search(ctx, &proto.SearchRequest{Platform: platform, Architecture: architecture, Query: query}) if connErr != nil{ logger.Fatal(connErr)