get.porter.sh/porter@v1.3.0/pkg/pkgmgmt/metadata.go (about) 1 package pkgmgmt 2 3 var _ PackageMetadata = Metadata{} 4 5 // Metadata about an installed package. 6 type Metadata struct { 7 // Name of package. 8 Name string `json:"name"` 9 // VersionInfo for the package. 10 VersionInfo 11 } 12 13 // GetName of the installed package. 14 func (m Metadata) GetName() string { 15 return m.Name 16 } 17 18 // GetVersionInfo for the installed package. 19 func (m Metadata) GetVersionInfo() VersionInfo { 20 return m.VersionInfo 21 } 22 23 // VersionInfo contains metadata from running the version command against the 24 // client executable. 25 type VersionInfo struct { 26 Version string `json:"version"` 27 Commit string `json:"commit"` 28 Author string `json:"author,omitempty"` 29 } 30 31 // PackageMetadata is a common interface for packages managed by Porter. 32 type PackageMetadata interface { 33 // GetName of the installed package. 34 GetName() string 35 36 // GetVersionInfo for the installed package. 37 GetVersionInfo() VersionInfo 38 } 39 40 // PackageListing represents discovery information for a package 41 type PackageListing struct { 42 Name string `json:"name"` 43 Author string `json:"author"` 44 Description string `json:"description"` 45 URL string `json:"URL"` 46 } 47 48 // PackageList is a collection of PackageListings 49 type PackageList []PackageListing 50 51 // PackageList implements the sort.Interface for []PackageListing 52 // based on the Name field. 53 func (rml PackageList) Len() int { 54 return len(rml) 55 } 56 func (rml PackageList) Swap(i, j int) { 57 rml[i], rml[j] = rml[j], rml[i] 58 } 59 func (rml PackageList) Less(i, j int) bool { 60 return rml[i].Name < rml[j].Name 61 }