{"record":{"id":"0436cd62bb29b2fd","repo":"golang/go","slug":"import-path-does-not-begin-with-hostname","errorCode":null,"errorMessage":"import path does not begin with hostname","messagePattern":"import path does not begin with hostname","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/vcs/vcs.go","lineNumber":979,"sourceCode":"\t\t}\n\n\t\treturn httpURL, true\n\t}\n\treturn \"\", false\n}\n\n// urlForImportPath returns a partially-populated URL for the given Go import path.\n//\n// The URL leaves the Scheme field blank so that web.Get will try any scheme\n// allowed by the selected security mode.\nfunc urlForImportPath(importPath string) (*urlpkg.URL, error) {\n\tslash := strings.Index(importPath, \"/\")\n\tif slash < 0 {\n\t\tslash = len(importPath)\n\t}\n\thost, path := importPath[:slash], importPath[slash:]\n\tif !strings.Contains(host, \".\") {\n\t\treturn nil, errors.New(\"import path does not begin with hostname\")\n\t}\n\tif len(path) == 0 {\n\t\tpath = \"/\"\n\t}\n\treturn &urlpkg.URL{Host: host, Path: path, RawQuery: \"go-get=1\"}, nil\n}\n\n// repoRootForImportDynamic finds a *RepoRoot for a custom domain that's not\n// statically known by repoRootFromVCSPaths.\n//\n// This handles custom import paths like \"name.tld/pkg/foo\" or just \"name.tld\".\nfunc repoRootForImportDynamic(importPath string, mod ModuleMode, security web.SecurityMode) (*RepoRoot, error) {\n\turl, err := urlForImportPath(importPath)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tresp, err := web.Get(security, url)\n\tif err != nil {","sourceCodeStart":961,"sourceCodeEnd":997,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/vcs/vcs.go#L961-L997","documentation":"urlForImportPath splits an import path at the first `/`; the first segment is treated as the host and must contain a dot (look like a domain). If it doesn't, the path is rejected because module discovery needs a real hostname to query.","triggerScenarios":"`go get`/import of a path whose first segment has no dot, e.g. `go get foo` or `import \"foo\"`.","commonSituations":"Typos; forgotten domain prefix; trying to use a bare local name as a remote module.","solutions":["Provide a complete import path beginning with a hostname (e.g. github.com/user/repo).","For local code, use a replace directive or a properly rooted module path."],"exampleFix":"# before\n$ go get foo\n\n# after\n$ go get github.com/user/foo","handlingStrategy":"validation","validationCode":"// Reject import paths whose first segment has no dot.\nfunc looksLikeHostPath(p string) error {\n    host := p\n    if i := strings.Index(p, \"/\"); i >= 0 { host = p[:i] }\n    if !strings.Contains(host, \".\") { return errors.New(\"path must begin with a hostname\") }\n    return nil\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Always use fully-qualified import paths (domain/repo[/sub]).","Validate user-supplied module paths before go get."],"tags":["import","vcs","hostname","validation"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}