Moved some stuff fom the Handler to the ProtoWrapper
This commit is contained in:
parent
0e77fe3e3d
commit
f848f8ab14
1 changed files with 46 additions and 0 deletions
46
ProtoHandler/ProtoWrapper.go
Normal file
46
ProtoHandler/ProtoWrapper.go
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
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
|
||||
}
|
||||
Reference in a new issue