module

package standard library
Version: go1.13.15 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2020 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package module defines the module.Version type along with support code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanonicalVersion

func CanonicalVersion(v string) string

CanonicalVersion returns the canonical form of the version string v. It is the same as semver.Canonical(v) except that it preserves the special build suffix "+incompatible".

func Check

func Check(path, version string) error

Check checks that a given module path, version pair is valid. In addition to the path being a valid module path and the version being a valid semantic version, the two must correspond. For example, the path "yaml/v2" only corresponds to semantic versions beginning with "v2.".

func CheckFilePath

func CheckFilePath(path string) error

CheckFilePath checks whether a slash-separated file path is valid.

func CheckImportPath

func CheckImportPath(path string) error

CheckImportPath checks that an import path is valid.

func CheckPath

func CheckPath(path string) error

CheckPath checks that a module path is valid.

func DecodePath

func DecodePath(encoding string) (path string, err error)

DecodePath returns the module path of the given safe encoding. It fails if the encoding is invalid or encodes an invalid path.

func DecodeVersion

func DecodeVersion(encoding string) (v string, err error)

DecodeVersion returns the version string for the given safe encoding. It fails if the encoding is invalid or encodes an invalid version. Versions are allowed to be in non-semver form but must be valid file names and not contain exclamation marks.

func EncodePath

func EncodePath(path string) (encoding string, err error)

EncodePath returns the safe encoding of the given module path. It fails if the module path is invalid.

func EncodeVersion

func EncodeVersion(v string) (encoding string, err error)

EncodeVersion returns the safe encoding of the given module version. Versions are allowed to be in non-semver form but must be valid file names and not contain exclamation marks.

func MatchPathMajor

func MatchPathMajor(v, pathMajor string) error

MatchPathMajor returns a non-nil error if the semantic version v does not match the path major version pathMajor.

func PathMajorPrefix added in go1.13

func PathMajorPrefix(pathMajor string) string

PathMajorPrefix returns the major-version tag prefix implied by pathMajor. An empty PathMajorPrefix allows either v0 or v1.

Note that MatchPathMajor may accept some versions that do not actually begin with this prefix: namely, it accepts a 'v0.0.0-' prefix for a '.v1' pathMajor, even though that pathMajor implies 'v1' tagging.

func Sort

func Sort(list []Version)

Sort sorts the list by Path, breaking ties by comparing Versions.

func SplitPathVersion

func SplitPathVersion(path string) (prefix, pathMajor string, ok bool)

SplitPathVersion returns prefix and major version such that prefix+pathMajor == path and version is either empty or "/vN" for N >= 2. As a special case, gopkg.in paths are recognized directly; they require ".vN" instead of "/vN", and for all N, not just N >= 2.

func VersionError added in go1.13

func VersionError(v Version, err error) error

VersionError returns a ModuleError derived from a Version and error.

Types

type InvalidVersionError added in go1.13

type InvalidVersionError struct {
	Version string
	Pseudo  bool
	Err     error
}

An InvalidVersionError indicates an error specific to a version, with the module path unknown or specified externally.

A ModuleError may wrap an InvalidVersionError, but an InvalidVersionError must not wrap a ModuleError.

func (*InvalidVersionError) Error added in go1.13

func (e *InvalidVersionError) Error() string

func (*InvalidVersionError) Unwrap added in go1.13

func (e *InvalidVersionError) Unwrap() error

type ModuleError added in go1.13

type ModuleError struct {
	Path    string
	Version string
	Err     error
}

A ModuleError indicates an error specific to a module.

func (*ModuleError) Error added in go1.13

func (e *ModuleError) Error() string

func (*ModuleError) Unwrap added in go1.13

func (e *ModuleError) Unwrap() error

type Version

type Version struct {
	Path string

	// Version is usually a semantic version in canonical form.
	// There are two exceptions to this general rule.
	// First, the top-level target of a build has no specific version
	// and uses Version = "".
	// Second, during MVS calculations the version "none" is used
	// to represent the decision to take no version of a given module.
	Version string `json:",omitempty"`
}

A Version is defined by a module path and version pair.

Source Files

Jump to

Keyboard shortcuts

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