Source File
module.go
Belonging Package
golang.org/x/mod/module
package module
import (
errors
)
func ( Version, error) error {
var *ModuleError
if errors.As(, &) && .Path == .Path && .Version == .Version {
return
}
return &ModuleError{
Path: .Path,
Version: .Version,
Err: ,
}
}
func ( *ModuleError) () string {
if , := .Err.(*InvalidVersionError); {
return fmt.Sprintf("%s@%s: invalid %s: %v", .Path, .Version, .noun(), .Err)
}
if .Version != "" {
return fmt.Sprintf("%s@%s: %v", .Path, .Version, .Err)
}
return fmt.Sprintf("module %s: %v", .Path, .Err)
}
func ( *ModuleError) () error { return .Err }
func ( *InvalidVersionError) () string {
if .Pseudo {
return "pseudo-version"
}
return "version"
}
func ( *InvalidVersionError) () string {
return fmt.Sprintf("%s %q invalid: %s", .noun(), .Version, .Err)
}
func ( *InvalidVersionError) () error { return .Err }
func (, string) error {
if := CheckPath(); != nil {
return
}
if !semver.IsValid() {
return &ModuleError{
Path: ,
Err: &InvalidVersionError{Version: , Err: errors.New("not a semantic version")},
}
}
, , := SplitPathVersion()
if := CheckPathMajor(, ); != nil {
return &ModuleError{Path: , Err: }
}
return nil
}
func ( string) error {
if := checkPath(, false); != nil {
return fmt.Errorf("malformed module path %q: %v", , )
}
:= strings.Index(, "/")
if < 0 {
= len()
}
if == 0 {
return fmt.Errorf("malformed module path %q: leading slash", )
}
if !strings.Contains([:], ".") {
return fmt.Errorf("malformed module path %q: missing dot in first path element", )
}
if [0] == '-' {
return fmt.Errorf("malformed module path %q: leading dash in first path element", )
}
for , := range [:] {
if !firstPathOK() {
return fmt.Errorf("malformed module path %q: invalid char %q in first path element", , )
}
}
if , , := SplitPathVersion(); ! {
return fmt.Errorf("malformed module path %q: invalid version", )
}
return nil
}
func ( string, bool) error {
if !utf8.ValidString() {
return fmt.Errorf("invalid UTF-8")
}
if == "" {
return fmt.Errorf("empty string")
}
if [0] == '-' {
return fmt.Errorf("leading dash")
}
if strings.Contains(, "//") {
return fmt.Errorf("double slash")
}
if [len()-1] == '/' {
return fmt.Errorf("trailing slash")
}
:= 0
for , := range {
if == '/' {
if := checkElem([:], ); != nil {
return
}
= + 1
}
}
if := checkElem([:], ); != nil {
return
}
return nil
}
func ( string, bool) error {
if == "" {
return fmt.Errorf("empty path element")
}
if strings.Count(, ".") == len() {
return fmt.Errorf("invalid path element %q", )
}
if [0] == '.' && ! {
return fmt.Errorf("leading dot in path element")
}
if [len()-1] == '.' {
return fmt.Errorf("trailing dot in path element")
}
:= pathOK
if {
= fileNameOK
}
for , := range {
if !() {
return fmt.Errorf("invalid char %q", )
}
}
return nil
}
var badWindowsNames = []string{
"CON",
"PRN",
"AUX",
"NUL",
"COM1",
"COM2",
"COM3",
"COM4",
"COM5",
"COM6",
"COM7",
"COM8",
"COM9",
"LPT1",
"LPT2",
"LPT3",
"LPT4",
"LPT5",
"LPT6",
"LPT7",
"LPT8",
"LPT9",
}
func ( string) (, string, bool) {
if strings.HasPrefix(, "gopkg.in/") {
return splitGopkgIn()
}
:= len()
:= false
for > 0 && ('0' <= [-1] && [-1] <= '9' || [-1] == '.') {
if [-1] == '.' {
= true
}
--
}
if <= 1 || == len() || [-1] != 'v' || [-2] != '/' {
return , "", true
}
, = [:-2], [-2:]
if || len() <= 2 || [2] == '0' || == "/v1" {
return , "", false
}
return , , true
}
func (, string) bool {
return CheckPathMajor(, ) == nil
}
return nil
}
:= semver.Major()
if == "" {
if == "v0" || == "v1" || semver.Build() == "+incompatible" {
return nil
}
= "v0 or v1"
} else if [0] == '/' || [0] == '.' {
if == [1:] {
return nil
}
= [1:]
}
return &InvalidVersionError{
Version: ,
Err: fmt.Errorf("should be %s, not %s", , semver.Major()),
}
}
func ( string) string {
if == "" {
return ""
}
if [0] != '/' && [0] != '.' {
panic("pathMajor suffix " + + " passed to PathMajorPrefix lacks separator")
}
if strings.HasPrefix(, ".v") && strings.HasSuffix(, "-unstable") {
= strings.TrimSuffix(, "-unstable")
}
:= [1:]
if != semver.Major() {
panic("pathMajor suffix " + + "passed to PathMajorPrefix is not a valid major version")
}
return
}
func ( string) ( string, error) {
, := unescapeString()
if ! {
return "", fmt.Errorf("invalid escaped version %q", )
}
if := checkElem(, true); != nil {
return "", fmt.Errorf("invalid escaped version %q: %v", , )
}
return , nil
}
func ( string) (string, bool) {
var []byte
:= false
for , := range {
if >= utf8.RuneSelf {
return "", false
}
if {
= false
if < 'a' || 'z' < {
return "", false
}
= append(, byte(+'A'-'a'))
continue
}
if == '!' {
= true
continue
}
if 'A' <= && <= 'Z' {
return "", false
}
= append(, byte())
}
if {
return "", false
}
return string(), true
}
for := 0; < len(); ++ {
if [] == '/' {
if == 0 {
= [:]
break
}
--
}
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |