mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 08:23:15 +01:00
43 lines
791 B
Go
43 lines
791 B
Go
package distro
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
hashiVer "github.com/hashicorp/go-version"
|
|
)
|
|
|
|
type Distro struct {
|
|
Type Type
|
|
Version *hashiVer.Version
|
|
RawVersion string
|
|
}
|
|
|
|
func NewDistro(t Type, ver string) (Distro, error) {
|
|
verObj, err := hashiVer.NewVersion(ver)
|
|
if err != nil {
|
|
return Distro{}, fmt.Errorf("could not create distro version: %w", err)
|
|
}
|
|
return Distro{
|
|
Type: t,
|
|
Version: verObj,
|
|
RawVersion: ver,
|
|
}, nil
|
|
}
|
|
|
|
func (d Distro) MajorVersion() string {
|
|
return fmt.Sprintf("%d", d.Version.Segments()[0])
|
|
}
|
|
|
|
func (d Distro) FullVersion() string {
|
|
return d.RawVersion
|
|
}
|
|
|
|
func (d Distro) String() string {
|
|
return fmt.Sprintf("%s %s", d.Type, d.RawVersion)
|
|
}
|
|
|
|
// Name provides a string repr of the distro
|
|
func (d Distro) Name() string {
|
|
return d.Type.String()
|
|
}
|