Imports #
"errors"
"fmt"
"path"
"sort"
"strings"
"unicode"
"unicode/utf8"
"golang.org/x/mod/semver"
"errors"
"fmt"
"strings"
"time"
"golang.org/x/mod/internal/lazyregexp"
"golang.org/x/mod/semver"
"errors"
"fmt"
"path"
"sort"
"strings"
"unicode"
"unicode/utf8"
"golang.org/x/mod/semver"
"errors"
"fmt"
"strings"
"time"
"golang.org/x/mod/internal/lazyregexp"
"golang.org/x/mod/semver"
const PseudoVersionTimestampFormat = "20060102150405"
badWindowsNames are the reserved file path elements on Windows. See https://docs.microsoft.com/en-us/windows/desktop/fileio/naming-a-file
var badWindowsNames = []string{...}
var errPseudoSyntax = *ast.CallExpr
const filePath
const importPath
const modulePath pathKind = iota
var pseudoVersionRE = *ast.CallExpr
pathKind indicates what kind of path we're checking. Module paths, import paths, and file paths have different restrictions.
type pathKind int
An InvalidPathError indicates a module, import, or file path doesn't satisfy all naming constraints. See [CheckPath], [CheckImportPath], and [CheckFilePath] for specific restrictions.
type InvalidPathError struct {
Kind string
Path string
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.
type InvalidVersionError struct {
Version string
Pseudo bool
Err error
}
A ModuleError indicates an error specific to a module.
type ModuleError struct {
Path string
Version string
Err error
}
A Version (for clients, a module.Version) is defined by a module path and version pair. These are stored in their plain (unescaped) form.
type Version struct {
Path string
Version string `json:",omitempty"`
}
CanonicalVersion returns the canonical form of the version string v. It is the same as [semver.Canonical] except that it preserves the special build suffix "+incompatible".
func CanonicalVersion(v string) string
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 Check(path string, version string) error
CheckFilePath checks that a slash-separated file path is valid. The definition of a valid file path is the same as the definition of a valid import path except that the set of allowed characters is larger: all Unicode letters, ASCII digits, the ASCII space character (U+0020), and the ASCII punctuation characters “!#$%&()+,-.=@[]^_{}~”. (The excluded punctuation characters, " * < > ? ` ' | / \ and :, have special meanings in certain shells or operating systems.) CheckFilePath may be less restrictive in the future, but see the top-level package documentation for additional information about subtleties of Unicode.
func CheckFilePath(path string) error
CheckImportPath checks that an import path is valid. A valid import path consists of one or more valid path elements separated by slashes (U+002F). (It must not begin with nor end in a slash.) A valid path element is a non-empty string made up of ASCII letters, ASCII digits, and limited ASCII punctuation: - . _ and ~. It must not end with a dot (U+002E), nor contain two dots in a row. The element prefix up to the first dot must not be a reserved file name on Windows, regardless of case (CON, com1, NuL, and so on). The element must not have a suffix of a tilde followed by one or more ASCII digits (to exclude paths elements that look like Windows short-names). CheckImportPath may be less restrictive in the future, but see the top-level package documentation for additional information about subtleties of Unicode.
func CheckImportPath(path string) error
CheckPath checks that a module path is valid. A valid module path is a valid import path, as checked by [CheckImportPath], with three additional constraints. First, the leading path element (up to the first slash, if any), by convention a domain name, must contain only lower-case ASCII letters, ASCII digits, dots (U+002E), and dashes (U+002D); it must contain at least one dot and cannot start with a dash. Second, for a final path element of the form /vN, where N looks numeric (ASCII digits and dots) must not begin with a leading zero, must not be /v1, and must not contain any dots. For paths beginning with "gopkg.in/", this second requirement is replaced by a requirement that the path follow the gopkg.in server's conventions. Third, no path element may begin with a dot.
func CheckPath(path string) (err error)
CheckPathMajor returns a non-nil error if the semantic version v does not match the path major version pathMajor.
func CheckPathMajor(v string, pathMajor string) error
func (e *ModuleError) Error() string
func (e *InvalidVersionError) Error() string
func (e *InvalidPathError) Error() string
EscapePath returns the escaped form of the given module path. It fails if the module path is invalid.
func EscapePath(path string) (escaped string, err error)
EscapeVersion returns the escaped form 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 EscapeVersion(v string) (escaped string, err error)
IsPseudoVersion reports whether v is a pseudo-version.
func IsPseudoVersion(v string) bool
IsZeroPseudoVersion returns whether v is a pseudo-version with a zero base, timestamp, and revision, as returned by [ZeroPseudoVersion].
func IsZeroPseudoVersion(v string) bool
MatchPathMajor reports whether the semantic version v matches the path major version pathMajor. MatchPathMajor returns true if and only if [CheckPathMajor] returns nil.
func MatchPathMajor(v string, pathMajor string) bool
MatchPrefixPatterns reports whether any path prefix of target matches one of the glob patterns (as defined by [path.Match]) in the comma-separated globs list. This implements the algorithm used when matching a module path to the GOPRIVATE environment variable, as described by 'go help module-private'. It ignores any empty or malformed patterns in the list. Trailing slashes on patterns are ignored.
func MatchPrefixPatterns(globs string, target string) bool
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 PathMajorPrefix(pathMajor string) string
PseudoVersion returns a pseudo-version for the given major version ("v1") preexisting older tagged version ("" or "v1.2.3" or "v1.2.3-pre"), revision time, and revision identifier (usually a 12-byte commit hash prefix).
func PseudoVersion(major string, older string, t time.Time, rev string) string
PseudoVersionBase returns the canonical parent version, if any, upon which the pseudo-version v is based. If v has no parent version (that is, if it is "vX.0.0-[…]"), PseudoVersionBase returns the empty string and a nil error.
func PseudoVersionBase(v string) (string, error)
PseudoVersionRev returns the revision identifier of the pseudo-version v. It returns an error if v is not a pseudo-version.
func PseudoVersionRev(v string) (rev string, err error)
PseudoVersionTime returns the time stamp of the pseudo-version v. It returns an error if v is not a pseudo-version or if the time stamp embedded in the pseudo-version is not a valid time.
func PseudoVersionTime(v string) (time.Time, error)
Sort sorts the list by Path, breaking ties by comparing [Version] fields. The Version fields are interpreted as semantic versions (using [semver.Compare]) optionally followed by a tie-breaking suffix introduced by a slash character, like in "v0.0.1/go.mod".
func Sort(list []Version)
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. SplitPathVersion returns with ok = false when presented with a path whose last path element does not satisfy the constraints applied by [CheckPath], such as "example.com/pkg/v1" or "example.com/pkg/v1.2".
func SplitPathVersion(path string) (prefix string, pathMajor string, ok bool)
String returns a representation of the Version suitable for logging (Path@Version, or just Path if Version is empty).
func (m Version) String() string
UnescapePath returns the module path for the given escaped path. It fails if the escaped path is invalid or describes an invalid path.
func UnescapePath(escaped string) (path string, err error)
UnescapeVersion returns the version string for the given escaped version. It fails if the escaped form is invalid or describes an invalid version. Versions are allowed to be in non-semver form but must be valid file names and not contain exclamation marks.
func UnescapeVersion(escaped string) (v string, err error)
func (e *InvalidPathError) Unwrap() error
func (e *InvalidVersionError) Unwrap() error
func (e *ModuleError) Unwrap() error
VersionError returns a [ModuleError] derived from a [Version] and error, or err itself if it is already such an error.
func VersionError(v Version, err error) error
ZeroPseudoVersion returns a pseudo-version with a zero timestamp and revision, which may be used as a placeholder.
func ZeroPseudoVersion(major string) string
checkElem checks whether an individual path element is valid.
func checkElem(elem string, kind pathKind) error
checkPath checks that a general path is valid. kind indicates what specific constraints should be applied. checkPath returns an error describing why the path is not valid. Because these checks apply to module, import, and file paths, and because other checks may be applied, the caller is expected to wrap this error with [InvalidPathError].
func checkPath(path string, kind pathKind) error
decDecimal returns the decimal string decremented by 1, or the empty string if the decimal is all zeroes.
func decDecimal(decimal string) string
func escapeString(s string) (escaped string, err error)
fileNameOK reports whether r can appear in a file name. For now we allow all Unicode letters but otherwise limit to pathOK plus a few more punctuation characters. If we expand the set of allowed characters here, we have to work harder at detecting potential case-folding and normalization collisions. See note about "escaped paths" above.
func fileNameOK(r rune) bool
firstPathOK reports whether r can appear in the first element of a module path. The first element of the path must be an LDH domain name, at least for now. To avoid case ambiguity, the domain name must be entirely lower case.
func firstPathOK(r rune) bool
importPathOK reports whether r can appear in a package import path element. Import paths are intermediate between module paths and file paths: we allow disallow characters that would be confusing or ambiguous as arguments to 'go get' (such as '@' and ' ' ), but allow certain characters that are otherwise-unambiguous on the command line and historically used for some binary names (such as '++' as a suffix for compiler binaries and wrappers).
func importPathOK(r rune) bool
incDecimal returns the decimal string incremented by 1.
func incDecimal(decimal string) string
modPathOK reports whether r can appear in a module path element. Paths can be ASCII letters, ASCII digits, and limited ASCII punctuation: - . _ and ~. This matches what "go get" has historically recognized in import paths, and avoids confusing sequences like '%20' or '+' that would change meaning if used in a URL. TODO(rsc): We would like to allow Unicode letters, but that requires additional care in the safe encoding (see "escaped paths" above).
func modPathOK(r rune) bool
noun returns either "version" or "pseudo-version", depending on whether e.Version is a pseudo-version.
func (e *InvalidVersionError) noun() string
func parsePseudoVersion(v string) (base string, timestamp string, rev string, build string, err error)
splitGopkgIn is like SplitPathVersion but only for gopkg.in paths.
func splitGopkgIn(path string) (prefix string, pathMajor string, ok bool)
func unescapeString(escaped string) (string, bool)
Generated with Arrow