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/PackageMetadata.go

69 lines
1.7 KiB
Go

package ProtoHandler
import (
proto "lotus-pm.net/proto"
"lpm-cli/Lotus"
)
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())
}