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/ProtoHandler/ProtoWrapper.go

46 lines
No EOL
1.1 KiB
Go

package ProtoHandler
import (
"golang.org/x/net/context"
"google.golang.org/grpc"
"lpm-cli/Lotus"
proto "lpm-cli/Proto/lpm/go"
"time"
)
type ProtoWrapper struct{}
func (protoWrap ProtoWrapper) CreateConnection(address string) *grpc.ClientConn {
logger := Lotus.DetailedLogger("ProtoHandler", "createConnection")
conn, err := grpc.Dial(address, grpc.WithInsecure())
if err != nil {
logger.Fatal(err)
}
return conn
}
func (protoWrap ProtoWrapper) CreateRegistryClient(conn *grpc.ClientConn) (proto.LpmRegistryClient, context.Context, context.CancelFunc) {
lrc := proto.NewLpmRegistryClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), time.Second * 10)
return lrc, ctx, cancel
}
func (protoWrap ProtoWrapper) ParsePackages(res *proto.SearchResponse, reg Lotus.Registry) []Package {
var packages []Package
for _, pkg := range res.GetPackages() {
var tmpMeta PackageMetadata
tmpMeta.FillMetadata(pkg)
packages = append(packages, Package {
PackageMetadata: tmpMeta,
Register: Lotus.Registry{
Register: reg.Register,
Address: reg.Address,
},
})
}
return packages
}