Documentation
¶
Index ¶
- Variables
- type Version
- func (v Version) Build() string
- func (v Version) Canonical() string
- func (v Version) Major() string
- func (v Version) MajorMinor() string
- func (v Version) MarshalText() (text []byte, err error)
- func (v Version) Prerelease() string
- func (v Version) String() string
- func (v *Version) UnmarshalText(text []byte) error
Constants ¶
This section is empty.
Variables ¶
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 ¶
MustParse allocates a new Version instance and panics if the given string is not a valid semantic version.
func Parse ¶
Parse allocates a new Version instance.
Returns ErrInvalidSemver if `v` is an invalid semantic version.
func (Version) Build ¶
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 ¶
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 ¶
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 ¶
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 (Version) Prerelease ¶
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.