tailscale.comtailscale.com/util/cmpver Index | Files

package cmpver

import "tailscale.com/util/cmpver"

Package cmpver implements a variant of debian version number comparison.

A version is a string consisting of alternating non-numeric and numeric fields. When comparing two versions, each one is broken down into its respective fields, and the fields are compared pairwise. The comparison is lexicographic for non-numeric fields, numeric for numeric fields. The first non-equal field pair determines the ordering of the two versions.

This comparison scheme is a simplified version of Debian's version number comparisons. Debian differs in a few details of lexicographical field comparison, where certain characters have special meaning and ordering. We don't need that, because Tailscale version numbers don't need it.

Index

Functions

func Compare

func Compare(v1, v2 string) int

Compare returns an integer comparing two strings as version numbers. The result will be -1, 0, or 1 representing the sign of v1 - v2:

Compare(v1, v2)  < 0  if v1  < v2
                == 0  if v1 == v2
                 > 0  if v1  > v2

func Less

func Less(v1, v2 string) bool

Less reports whether v1 is less than v2.

Note that "12" is less than "12.0".

func LessEq

func LessEq(v1, v2 string) bool

LessEq reports whether v1 is less than or equal to v2.

Note that "12" is less than "12.0".

Source Files

version.go

Version
v1.84.0 (latest)
Published
May 21, 2025
Platform
linux/amd64
Imports
3 packages
Last checked
2 days ago

Tools for package owners.