Documentation
¶
Overview ¶
Package semver provides utilities for parsing and validating semantic versions.
Semantic versioning follows the MAJOR.MINOR.PATCH[+extra] format (optionally prefixed with 'v'). Examples: "1.2.3", "v1.2.3-beta", "2.0.0+build.123"
This package is used internally by depsdiff to analyze version changes and provide semantic version type information (MAJOR, MINOR, PATCH, EXTRA updates).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsValid ¶
IsValid reports whether value is a valid semantic version string.
Valid formats include:
- "1.2.3"
- "v1.2.3" (with optional 'v' prefix)
- "1.2.3-beta" (with pre-release identifier)
- "1.2.3+build.123" (with build metadata)
- "1.2.3-beta+build.123" (with both)
Returns true if the version matches semantic version format, false otherwise.
func Parse ¶
Parse parses a semantic version string and returns its components.
The input string may optionally be prefixed with 'v' (e.g., "v1.2.3" or "1.2.3"). The version string must follow semantic version format: MAJOR.MINOR.PATCH[+extra].
Parameters:
- version: A semantic version string to parse
Returns:
- *Semver: Pointer to parsed version components (Major, Minor, Patch, Extra), or nil on error
- error: InvalidVersionError if the version string format is invalid, or InvalidComponentError if version components cannot be parsed as integers
Example:
semver, err := Parse("1.2.3-beta")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Major: %d, Minor: %d\n", semver.Major, semver.Minor)
Types ¶
type InvalidComponentError ¶
type InvalidComponentError struct {
Version string
}
InvalidComponentError is returned when semantic version components cannot be parsed as integers.
func (InvalidComponentError) Error ¶
func (e InvalidComponentError) Error() string
type InvalidVersionError ¶
type InvalidVersionError struct {
Version string
}
InvalidVersionError is returned when a version string does not match semantic version format.
func (InvalidVersionError) Error ¶
func (e InvalidVersionError) Error() string