Documentation
¶
Overview ¶
Package version provides comprehensive version comparison for multiple ecosystems. It supports semver (npm, Go, Cargo), PEP 440 (Python), Debian, RPM, Alpine, and Maven.
Index ¶
- func Compare(v1, v2 string, format Format) (int, error)
- func CompareAlpine(v1, v2 string) (int, error)
- func CompareDebian(v1, v2 string) (int, error)
- func CompareGeneric(v1, v2 string) (int, error)
- func CompareMaven(v1, v2 string) (int, error)
- func ComparePEP440(v1, v2 string) (int, error)
- func CompareRPM(v1, v2 string) (int, error)
- func CompareSemver(v1, v2 string) (int, error)
- func InRange(version, introduced, fixed string, format Format) (bool, error)
- func IsDistroVersion(v string) bool
- func IsFixed(version, fixVersion string, format Format) (bool, error)
- func MustCompare(v1, v2 string, format Format) int
- func ParseSemverConstraint(constraint string) (*semver.Constraints, error)
- func SafeCompare(v1, v2 string, format Format) (int, error)
- func SemverSatisfies(version, constraint string) (bool, error)
- func VersionsComparable(v1, v2, ecosystem string) bool
- type AlpineVersion
- type CompareResult
- type DebianVersion
- type Format
- type GenericVersion
- type MavenVersion
- type PEP440Version
- type RPMVersion
- type SemVer
- type Version
- type VulnerabilityStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compare ¶
Compare compares two version strings using the specified format. Returns -1 if v1 < v2, 0 if v1 == v2, 1 if v1 > v2. Returns error if versions cannot be compared.
func CompareAlpine ¶
CompareAlpine compares two Alpine versions. Format: version-rN where N is the revision number.
func CompareDebian ¶
CompareDebian compares two Debian versions. Format: [epoch:]upstream_version[-debian_revision] Comparison order: epoch (numeric) > upstream > revision Uses Debian string comparison algorithm where ~ sorts before empty.
func CompareGeneric ¶
CompareGeneric performs a loose version comparison that works for most formats. It splits versions on common delimiters and compares segments numerically when possible.
func CompareMaven ¶
CompareMaven compares two Maven versions. Qualifier ordering: SNAPSHOT < alpha < beta < milestone < rc < RELEASE/FINAL/GA < (none) < sp
func ComparePEP440 ¶
ComparePEP440 compares two PEP 440 Python versions. Ordering: dev < alpha < beta < rc < release < post Handles epochs (1!1.0.0) and strips local versions for comparison.
func CompareRPM ¶
CompareRPM compares two RPM versions. Format: [epoch:]version[-release] Comparison order: epoch (numeric) > version > release
func CompareSemver ¶
CompareSemver compares two semantic versions. Handles v prefix, prerelease ordering (alpha < beta < rc < release), and ignores build metadata in comparison.
func InRange ¶
InRange checks if a version is within an affected range. The range is [introduced, fixed) - introduced is inclusive, fixed is exclusive.
func IsDistroVersion ¶
IsDistroVersion returns true if the version appears to be from a distribution package.
func MustCompare ¶
MustCompare is like Compare but returns 0 on error.
func ParseSemverConstraint ¶
func ParseSemverConstraint(constraint string) (*semver.Constraints, error)
ParseSemverConstraint parses a semver constraint string. Supports: =, !=, >, <, >=, <=, ~, ^, and ranges.
func SafeCompare ¶
SafeCompare compares versions with format validation. Returns an error if versions are not comparable (different ecosystems).
func SemverSatisfies ¶
SemverSatisfies checks if a version satisfies a constraint.
func VersionsComparable ¶
VersionsComparable checks if two versions can be meaningfully compared. Returns false if one is a distro-packaged version and the other is upstream.
Types ¶
type AlpineVersion ¶
type AlpineVersion struct {
// contains filtered or unexported fields
}
AlpineVersion represents a parsed Alpine version.
func NewAlpineVersion ¶
func NewAlpineVersion(v string) *AlpineVersion
NewAlpineVersion creates a new AlpineVersion from a version string.
func (*AlpineVersion) Compare ¶
func (a *AlpineVersion) Compare(other Version) int
Compare implements Version.Compare.
func (*AlpineVersion) Format ¶
func (a *AlpineVersion) Format() Format
Format implements Version.Format.
func (*AlpineVersion) String ¶
func (a *AlpineVersion) String() string
String implements Version.String.
type CompareResult ¶
type CompareResult int
CompareResult represents the result of a version comparison.
const ( CompareLess CompareResult = -1 CompareEqual CompareResult = 0 CompareGreater CompareResult = 1 CompareError CompareResult = -2 // Versions not comparable )
type DebianVersion ¶
type DebianVersion struct {
// contains filtered or unexported fields
}
DebianVersion represents a parsed Debian version.
func NewDebianVersion ¶
func NewDebianVersion(v string) *DebianVersion
NewDebianVersion creates a new DebianVersion from a version string.
func (*DebianVersion) Compare ¶
func (d *DebianVersion) Compare(other Version) int
Compare implements Version.Compare.
func (*DebianVersion) Format ¶
func (d *DebianVersion) Format() Format
Format implements Version.Format.
func (*DebianVersion) String ¶
func (d *DebianVersion) String() string
String implements Version.String.
type Format ¶
type Format int
Format represents a version format/ecosystem.
func DetectFormat ¶
DetectFormat attempts to detect the version format from a version string. The hint parameter can provide additional context (e.g., ecosystem name).
func FormatForEcosystem ¶
FormatForEcosystem returns the expected version format for an ecosystem name.
func ParseFormat ¶
ParseFormat parses a format string into a Format.
type GenericVersion ¶
type GenericVersion struct {
// contains filtered or unexported fields
}
GenericVersion represents a generic version string.
func NewGenericVersion ¶
func NewGenericVersion(v string) *GenericVersion
NewGenericVersion creates a new GenericVersion from a version string.
func (*GenericVersion) Compare ¶
func (g *GenericVersion) Compare(other Version) int
Compare implements Version.Compare.
func (*GenericVersion) Format ¶
func (g *GenericVersion) Format() Format
Format implements Version.Format.
func (*GenericVersion) String ¶
func (g *GenericVersion) String() string
String implements Version.String.
type MavenVersion ¶
type MavenVersion struct {
// contains filtered or unexported fields
}
MavenVersion represents a parsed Maven version.
func NewMavenVersion ¶
func NewMavenVersion(v string) *MavenVersion
NewMavenVersion creates a new MavenVersion from a version string.
func (*MavenVersion) Compare ¶
func (m *MavenVersion) Compare(other Version) int
Compare implements Version.Compare.
func (*MavenVersion) Format ¶
func (m *MavenVersion) Format() Format
Format implements Version.Format.
func (*MavenVersion) String ¶
func (m *MavenVersion) String() string
String implements Version.String.
type PEP440Version ¶
type PEP440Version struct {
// contains filtered or unexported fields
}
PEP440Version wraps a pep440.Version for the Version interface.
func NewPEP440Version ¶
func NewPEP440Version(v string) (*PEP440Version, error)
NewPEP440Version creates a new PEP440Version from a version string.
func (*PEP440Version) Compare ¶
func (p *PEP440Version) Compare(other Version) int
Compare implements Version.Compare.
func (*PEP440Version) Format ¶
func (p *PEP440Version) Format() Format
Format implements Version.Format.
func (*PEP440Version) String ¶
func (p *PEP440Version) String() string
String implements Version.String.
type RPMVersion ¶
type RPMVersion struct {
// contains filtered or unexported fields
}
RPMVersion represents a parsed RPM version.
func NewRPMVersion ¶
func NewRPMVersion(v string) *RPMVersion
NewRPMVersion creates a new RPMVersion from a version string.
func (*RPMVersion) Compare ¶
func (r *RPMVersion) Compare(other Version) int
Compare implements Version.Compare.
type SemVer ¶
type SemVer struct {
// contains filtered or unexported fields
}
SemVer wraps a semver.Version for the Version interface.
func (*SemVer) Prerelease ¶
Prerelease returns the prerelease string.
type Version ¶
type Version interface {
// Compare returns -1 if v < other, 0 if v == other, 1 if v > other.
Compare(other Version) int
// String returns the original version string.
String() string
// Format returns the version format.
Format() Format
}
Version represents a parsed version that can be compared.
type VulnerabilityStatus ¶
type VulnerabilityStatus int
VulnerabilityStatus represents the vulnerability status of a version.
const ( StatusUnknown VulnerabilityStatus = iota StatusNotAffected // Version predates vulnerability or is past last_affected StatusVulnerable // Version is in affected range StatusFixed // Version >= fix version )
func CheckVulnerabilityStatus ¶
func CheckVulnerabilityStatus(current, introduced, fixed, lastAffected string, format Format) (VulnerabilityStatus, string)
CheckVulnerabilityStatus determines if a version is affected by a vulnerability.
Parameters:
- current: The version to check
- introduced: Version where vulnerability was introduced (empty = from beginning)
- fixed: Version where vulnerability was fixed (empty = no fix available)
- lastAffected: Last version affected (empty = use fixed for upper bound)
- format: The version format to use for comparison
Returns the vulnerability status and a human-readable explanation.
func (VulnerabilityStatus) String ¶
func (s VulnerabilityStatus) String() string
String returns the string representation of the status.