66 lines
No EOL
1.6 KiB
Go
66 lines
No EOL
1.6 KiB
Go
package ProtoHandler
|
|
|
|
import (
|
|
"lpm-cli/Lotus"
|
|
proto "lpm-cli/Proto/lpm/go"
|
|
)
|
|
|
|
type Package struct{
|
|
PackageMetadata PackageMetadata
|
|
Register Lotus.Registry
|
|
}
|
|
|
|
type PackageMetadata struct {
|
|
Publisher string
|
|
Name string
|
|
Version string
|
|
Description string
|
|
Tags []string
|
|
Labels map[string]string
|
|
PackageSize uint64
|
|
Checksums Checksums
|
|
Platform string
|
|
Architecture string
|
|
Dependencies []Dependency
|
|
}
|
|
|
|
|
|
func fillDependencies(protoDependency []*proto.Dependency) []Dependency {
|
|
dependencies := make([]Dependency, len(protoDependency))
|
|
|
|
for i, dep := range protoDependency{
|
|
dependencies[i].ID = dep.GetId()
|
|
dependencies[i].VersionFilter = dep.GetVersionFilter()
|
|
}
|
|
|
|
return dependencies
|
|
}
|
|
|
|
func fillChecksums(checksum []*proto.Checksum) Checksums {
|
|
checksums := Checksums{}
|
|
|
|
for i, chk := range checksum{
|
|
switch checksum[i].Algorithm{
|
|
case 0: checksums.MD5 = chk.Checksum
|
|
case 1: checksums.SHA1 = chk.Checksum
|
|
case 2: checksums.SHA256 = chk.Checksum
|
|
case 3: checksums.SHA512 = chk.Checksum
|
|
}
|
|
}
|
|
|
|
return checksums
|
|
}
|
|
|
|
func (pkgMeta *PackageMetadata) FillMetadata(protoData *proto.PackageMetadata) {
|
|
pkgMeta.Publisher = protoData.GetPublisher()
|
|
pkgMeta.Name = protoData.GetName()
|
|
pkgMeta.Version = protoData.GetVersion()
|
|
pkgMeta.Description = protoData.GetDescription()
|
|
pkgMeta.Tags = protoData.GetTags()
|
|
pkgMeta.Labels = protoData.GetLabels()
|
|
pkgMeta.PackageSize = protoData.GetPackageSize()
|
|
pkgMeta.Checksums = fillChecksums(protoData.GetChecksums())
|
|
pkgMeta.Platform = protoData.Platform
|
|
pkgMeta.Architecture = protoData.Architecture
|
|
pkgMeta.Dependencies = fillDependencies(protoData.GetDependencies())
|
|
} |