version

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrInvalidSemver the given string was not using the semantic version format.
	ErrInvalidSemver = errors.New("invalid semantic version")
)

Functions

This section is empty.

Types

type Version

type Version struct {
	// contains filtered or unexported fields
}

Version represents a semantic version following the MAJOR.MINOR.PATCH convention. It is used to convey meaning about the changes introduced in a software release.

Fields:

- Major: Incremented when making incompatible API changes (e.g., breaking changes).

- Minor: Incremented when adding functionality in a backward-compatible manner.

- Patch: Incremented for backward-compatible bug fixes.

Example:

For a version "2.3.1":

- Major = 2 (breaking changes introduced in version 2.0.0).

- Minor = 3 (new features added since version 2.0.0).

- Patch = 1 (bug fixes applied since version 2.3.0).

This structure implements encoding.TextMarshaler, encoding.TextUnmarshaler and fmt.Stringer for easier integration with external components.

func MustParse

func MustParse(value string) Version

MustParse allocates a new Version instance and panics if the given string is not a valid semantic version.

func Parse

func Parse(value string) (Version, error)

Parse allocates a new Version instance.

Returns ErrInvalidSemver if `v` is an invalid semantic version.

func (Version) Build

func (v Version) Build() string

Build returns the build suffix of the semantic version v. For example, Build("v2.1.0+meta") == "+meta". If v is an invalid semantic version string, Build returns the empty string.

func (Version) Canonical

func (v Version) Canonical() string

Canonical returns the canonical formatting of the semantic version v. It fills in any missing .MINOR or .PATCH and discards build metadata. Two semantic versions compare equal only if their canonical formattings are identical strings. The canonical invalid semantic version is the empty string.

func (Version) Major

func (v Version) Major() string

Major returns the major version prefix of the semantic version v. For example, Major("v2.1.0") == "v2". If v is an invalid semantic version string, Major returns the empty string.

func (Version) MajorMinor

func (v Version) MajorMinor() string

MajorMinor returns the major.minor version prefix of the semantic version v. For example, MajorMinor("v2.1.0") == "v2.1". If v is an invalid semantic version string, MajorMinor returns the empty string.

func (Version) MarshalText

func (v Version) MarshalText() (text []byte, err error)

func (Version) Prerelease

func (v Version) Prerelease() string

Prerelease returns the prerelease suffix of the semantic version v. For example, Prerelease("v2.1.0-pre+meta") == "-pre". If v is an invalid semantic version string, Prerelease returns the empty string.

func (Version) String

func (v Version) String() string

func (*Version) UnmarshalText

func (v *Version) UnmarshalText(text []byte) error

Jump to

Keyboard shortcuts

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