This repository has been archived on 2026-03-18. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
lotus-package-manager/Commands/Handler.go
2021-11-20 13:09:22 +01:00

39 lines
1,001 B
Go

package Commands
import (
"lpm-cli/Lotus"
"lpm-cli/ProtoHandler"
proto "lpm-cli/Proto/lpm/go"
)
func fetchPackages(platform string, architecture []string, query string, registry Lotus.Registry) *proto.SearchResponse {
var protoWrap ProtoHandler.ProtoWrapper
conn := protoWrap.CreateConnection(registry.Address)
defer conn.Close()
client, ctx, cancel := protoWrap.CreateRegistryClient(conn)
defer cancel()
res, _ := client.Search(ctx, &proto.SearchRequest{Platform: platform, Architecture: architecture, Query: query})
return res
}
func SearchPackages(platform string, architecture []string, query string) []ProtoHandler.Package {
var packages []ProtoHandler.Package
var protoWrap ProtoHandler.ProtoWrapper
registries := Lotus.GetRegistries()
for _, reg := range registries {
res := fetchPackages(platform, architecture, query, reg)
if res != nil{
for _, pkg := range protoWrap.ParsePackages(res, reg){
packages = append(packages, pkg)
}
}
}
return packages
}