Documentation
¶
Index ¶
- Variables
- type Level
- type Semver
- func (s *Semver) Compare(other *Semver) int
- func (s *Semver) Copy() *Semver
- func (s *Semver) Equals(other *Semver) bool
- func (s *Semver) FindDrift(base *Semver) (Level, bool, error)
- func (s *Semver) Increment(level Level)
- func (s *Semver) IncrementMajor()
- func (s *Semver) IncrementMinor()
- func (s *Semver) IncrementNew(level Level) Semver
- func (s *Semver) IncrementPatch()
- func (s *Semver) IncrementPrerelease()
- func (s *Semver) String() string
- func (s *Semver) WithVersionContext(v *Semver) *Semver
Constants ¶
This section is empty.
Variables ¶
var ( ErrVersionLessThanBase = errors.New("version is less than the starting base version") ErrNoDrift = errors.New("no version drift detected, versions are equal") ErrFailedVersionCompare = errors.New("failed to compare two versions") )
Errors for operations on semantic versions.
Functions ¶
This section is empty.
Types ¶
type Semver ¶
type Semver struct { Major uint64 Minor uint64 Patch uint64 Prerelease string Build string // contains filtered or unexported fields }
Semver represents a parsed semantic version.
func (*Semver) Compare ¶
Compare two versions to determine if one is less than (-1), equal to (0), or greater than (1) the other.
func (*Semver) Equals ¶
Equals checks whether one Semver is equal to another. Equality is determined by comparing the major/minor/patch/prerelease/build values. Since those values are all encoded into the string representation of the Semver, this just compares those strings.
func (*Semver) FindDrift ¶
FindDrift finds the first instance of version drift walking down the version components.
This will return an error if the version is less than the base version it is being compared to, or if the versions are equal.
Additionally, it tracks whether the pre-release version was incremented, allowing the caller to determine whether the drift is a normal version drift (0.0.1 -> 0.0.2), a prerelease drift (0.1.0-alpha.1 -> 0.1.0-alpha.2), or a version with prerelease drift (0.1.0 -> 0.2.0-alpha.1).
func (*Semver) IncrementMajor ¶
func (s *Semver) IncrementMajor()
IncrementMajor increments the major version of the Semver. In doing so, it resets lower version components, e.g. a major version bump from 0.1.2 would be 1.0.0.
func (*Semver) IncrementMinor ¶
func (s *Semver) IncrementMinor()
IncrementMinor increments the minor version of the Semver. In doing so, it resets lower version components, e.g. a minor version bump from 0.1.2 would be 0.2.0.
func (*Semver) IncrementNew ¶
IncrementNew creates a copy of the Semver and increments the new copy at the specified level.
func (*Semver) IncrementPatch ¶
func (s *Semver) IncrementPatch()
IncrementPatch increments the patch version of the Semver. In doing so, it resets lower version components, e.g. a patch version bump from 0.1.2 would be 0.1.3.
func (*Semver) IncrementPrerelease ¶
func (s *Semver) IncrementPrerelease()
IncrementPrerelease increments the prerelease version of the Semver.
func (*Semver) WithVersionContext ¶
WithVersionContext adds a contextual semantic version to the Semver.