semver

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package semver provides functionality for parsing, comparing, and manipulating semantic version strings according to the SemVer 2.0.0 spec.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeriveNext

func DeriveNext(highestChange ChangeLevel, currentVersion string) (string, error)

DeriveNext calculates the next version based on the highest change type and current version.

func MaxVersion

func MaxVersion(versionStrings ...string) string

MaxVersion returns the largest semantic version string among the provided version strings.

Types

type ChangeLevel

type ChangeLevel int

ChangeLevel represents the level of change, corresponding to semantic versioning.

const (
	// None indicates no change.
	None ChangeLevel = iota
	// Patch is for backward-compatible bug fixes.
	Patch
	// Minor is for backward-compatible new features.
	Minor
	// Major is for incompatible API changes.
	Major
)

func (ChangeLevel) String

func (c ChangeLevel) String() string

String converts a ChangeLevel to its string representation.

type Version

type Version struct {
	Major, Minor, Patch int
	// Prerelease is the non-numeric part of the prerelease string (e.g., "alpha", "beta").
	Prerelease string
	// PrereleaseSeparator is the separator between the pre-release string and
	// its version (e.g., ".").
	PrereleaseSeparator string
	// PrereleaseNumber is the numeric part of the pre-release string (e.g., "1", "21").
	PrereleaseNumber string
}

Version represents a semantic version.

func Parse

func Parse(versionString string) (*Version, error)

Parse parses a version string into a Version struct.

func (*Version) Compare

func (v *Version) Compare(other *Version) int

Compare returns an integer comparing two versions. The result is -1, 0, or 1 depending on whether v is less than, equal to, or greater than other.

func (*Version) String

func (v *Version) String() string

String formats a Version struct into a string.

Jump to

Keyboard shortcuts

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