semver

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package semver provides functions for parsing, validating, and bumping semantic version numbers according to the Semantic Versioning 2.0.0 specification. See https://semver.org/ for the full specification.

This package handles versions with or without a leading 'v' prefix and provides options to preserve or remove the prefix when formatting.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidVersion = errors.New("invalid version format")
	ErrInvalidBump    = errors.New("invalid bump type")
)

Common errors returned by semver operations

Functions

func BumpMajor

func BumpMajor(version string, useVPrefix bool) (string, error)

BumpMajor increments the major version number This resets the minor and patch numbers to 0 useVPrefix determines whether to add 'v' prefix to the output

func BumpMinor

func BumpMinor(version string, useVPrefix bool) (string, error)

BumpMinor increments the minor version number This resets the patch number to 0 useVPrefix determines whether to add 'v' prefix to the output

func BumpPatch

func BumpPatch(version string, useVPrefix bool) (string, error)

BumpPatch increments the patch version number useVPrefix determines whether to add 'v' prefix to the output

func BumpVersion added in v1.0.0

func BumpVersion(version string, bumpType BumpType, useVPrefix bool) (string, error)

BumpVersion increments a version number based on the bump type Returns the new version string and an error if the version is invalid useVPrefix determines whether to add 'v' prefix to the output (true = add 'v', false = no prefix)

func Compare

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

Compare compares two version strings and returns:

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

func FormatVersion added in v1.0.0

func FormatVersion(ver semver.Version, includePrefix bool) string

FormatVersion formats a semver.Version object as a string If includePrefix is true, the string will be prefixed with 'v'

func ParseVersion added in v1.0.0

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

ParseVersion parses a version string into its components Returns the parsed semver.Version and whether it had a v prefix

Types

type BumpType added in v1.0.0

type BumpType string

BumpType represents the type of version bump to perform

const (
	Major BumpType = "major"
	Minor BumpType = "minor"
	Patch BumpType = "patch"
)

Constants for the different types of version bumps

Jump to

Keyboard shortcuts

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