semver

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Version

type Version struct {
	Major         int
	Minor         int
	Patch         int
	PreRelease    string
	BuildMetadata string
}

Version represents a semantic version with major, minor, and patch numbers, an optional pre-release identifier (e.g., "alpha.1", "beta.2", "snapshot.20260204-153045"), and optional build metadata (e.g., "build.123").

func MustParse

func MustParse(s string) Version

MustParse parses a version string and panics if it fails Use only in tests or when the version string is known to be valid

func Parse

func Parse(s string) (Version, error)

Parse parses a semantic version string into a Version struct Accepts formats: "1.2.3", "v1.2.3", "1.2.3-alpha.1", "v1.2.3-beta.2"

func (Version) BaseVersion added in v0.4.0

func (v Version) BaseVersion() Version

BaseVersion returns a copy of this version without the PreRelease identifier

func (Version) Bump added in v0.2.0

func (v Version) Bump(changeType string) (Version, error)

Bump returns a new version with the specified change type applied. The returned version always has an empty PreRelease (clean bump). changeType should be one of: "patch", "minor", "major"

func (Version) Compare

func (v Version) Compare(other Version) int

Compare compares this version with another version Returns: -1 if v < other, 0 if v == other, 1 if v > other Per semver spec: pre-release versions have lower precedence than the associated normal version. When both have pre-release identifiers, they are compared lexicographically.

func (Version) IsPreRelease added in v0.4.0

func (v Version) IsPreRelease() bool

IsPreRelease returns true if this version has a pre-release identifier

func (Version) String

func (v Version) String() string

String returns the string representation of the version (e.g., "1.2.3", "1.2.3-alpha.1", "1.2.3+build.123")

func (Version) WithBuildMetadata added in v0.4.0

func (v Version) WithBuildMetadata(metadata string) Version

WithBuildMetadata returns a copy of this version with the given build metadata

func (Version) WithPreRelease added in v0.4.0

func (v Version) WithPreRelease(preRelease string) Version

WithPreRelease returns a copy of this version with the given pre-release identifier

Jump to

Keyboard shortcuts

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