Help us shape the future of Go! Take the 2026 Go Developer Survey

version

package
v0.1.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package version parses request version labels ("1", "1.1", "2.0.1") and resolves which version a request node runs.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoVersions     = errors.New("request has no versions")
	ErrPinnedMissing  = errors.New("pinned version does not exist")
	ErrDefaultMissing = errors.New("default version does not exist")
)

Errors returned by Resolve.

View Source
var ErrInvalidLabel = errors.New("invalid version label")

ErrInvalidLabel is returned for labels that are not dotted non-negative integers without leading zeros.

Functions

func Normalize

func Normalize(raw string) string

Normalize trims a typed label and strips a leading "v", "ver", "ver." or "version" (any case, with dots, colons or spaces after it) when a number follows: "Version 1.2" is "1.2". Anything else is returned trimmed and as typed, for Parse to accept or refuse. Every place that takes a label from a person (the GUI, the CLI, the library's own save) uses it, so they agree.

func Resolve

func Resolve(q Query) (Label, Source, error)

Resolve picks a version: the node's pin, then the run preference, then the flow preference (each only if available), then the request default, then the highest version. The returned label is the request's own label, so "2.0" is returned when the preference was "2".

Types

type Label

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

Label is a parsed version label. The zero value is not a valid label.

func Highest

func Highest(ls []Label) (Label, bool)

Highest returns the greatest label, or false when ls is empty.

func Parse

func Parse(s string) (Label, error)

Parse parses a label such as "1", "1.10" or "2.0.1".

func (Label) Compare

func (l Label) Compare(o Label) int

Compare orders labels numerically per segment. Missing trailing segments count as zero, so "1" and "1.0" are equal.

func (Label) String

func (l Label) String() string

String returns the label exactly as written.

type Query

type Query struct {
	Available  []Label
	Default    *Label
	Pinned     *Label
	RunPrefer  *Label
	FlowPrefer *Label
}

Query is everything that influences which version a request node runs. Nil fields are unset.

type Source

type Source int

Source says which rule chose the resolved version.

const (
	SourcePinned Source = iota + 1
	SourceRunPreference
	SourceFlowPreference
	SourceDefault
	SourceHighest
)

Resolution rules, in the order they are tried.

Jump to

Keyboard shortcuts

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