version

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package version provides version comparison and filtering utilities.

Index

Constants

View Source
const (
	// Latest represents the special "latest" version tag.
	Latest = "latest"
)

Variables

This section is empty.

Functions

func Compare

func Compare(v1, v2 string) (int, error)

Compare compares two version strings using semantic versioning. Returns:

-1 if v1 < v2
 0 if v1 == v2
 1 if v1 > v2

func CompareVersions

func CompareVersions(v1, v2 string) (int, error)

CompareVersions compares two version strings. Returns:

  • -1 if v1 < v2
  • 0 if v1 == v2
  • 1 if v1 > v2
  • error if either version is invalid

func ContainsVersion

func ContainsVersion(versions []string, target string) bool

ContainsVersion checks if a version string is in the list. Supports both exact matches and glob patterns (e.g., "1.21.x").

func FindMaxVersion

func FindMaxVersion(versions []string) (string, error)

FindMaxVersion finds the maximum version from a list of version strings. Returns empty string if the list is empty or all versions are invalid.

func IsDowngrade

func IsDowngrade(currentVersion, candidateVersion string) (bool, error)

IsDowngrade checks if changing from currentVersion to candidateVersion would be a downgrade.

func MatchesVersionPattern

func MatchesVersionPattern(pattern, target string) bool

MatchesVersionPattern checks if a target version matches a glob pattern. Supports patterns like "1.21.x" which matches any version starting with "1.21.".

func ParseVersion

func ParseVersion(version string) (*semver.Version, error)

ParseVersion parses a version string into a semver.Version. Returns an error if the version string is invalid.

Types

type VersionInfo

type VersionInfo struct {
	// Version is the version string.
	Version string
	// ReleaseDate is when this version was released.
	ReleaseDate time.Time
}

VersionInfo contains metadata about a specific version.

func FilterByUpdateDelay

func FilterByUpdateDelay(versions []VersionInfo, delay time.Duration) []VersionInfo

FilterByUpdateDelay filters versions based on release date and update delay. Only versions released before (now - delay) are returned. If delay is zero, all versions are returned.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL