Moved connection handler to Commands

This commit is contained in:
netbenix 2021-11-20 13:09:22 +01:00
parent 150037aa57
commit da2a4cdfd8
2 changed files with 39 additions and 82 deletions

39
Commands/Handler.go Normal file
View file

@ -0,0 +1,39 @@
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
}