golang/go · error
import path does not begin with hostname
Error message
import path does not begin with hostname
What it means
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.
Source
Thrown at src/cmd/go/internal/vcs/vcs.go:979
}
return httpURL, true
}
return "", false
}
// urlForImportPath returns a partially-populated URL for the given Go import path.
//
// The URL leaves the Scheme field blank so that web.Get will try any scheme
// allowed by the selected security mode.
func urlForImportPath(importPath string) (*urlpkg.URL, error) {
slash := strings.Index(importPath, "/")
if slash < 0 {
slash = len(importPath)
}
host, path := importPath[:slash], importPath[slash:]
if !strings.Contains(host, ".") {
return nil, errors.New("import path does not begin with hostname")
}
if len(path) == 0 {
path = "/"
}
return &urlpkg.URL{Host: host, Path: path, RawQuery: "go-get=1"}, nil
}
// repoRootForImportDynamic finds a *RepoRoot for a custom domain that's not
// statically known by repoRootFromVCSPaths.
//
// This handles custom import paths like "name.tld/pkg/foo" or just "name.tld".
func repoRootForImportDynamic(importPath string, mod ModuleMode, security web.SecurityMode) (*RepoRoot, error) {
url, err := urlForImportPath(importPath)
if err != nil {
return nil, err
}
resp, err := web.Get(security, url)
if err != nil {View on GitHub (pinned to b6b368adc5)
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.
Example fix
# before $ go get foo # after $ go get github.com/user/foo
Defensive patterns
Strategy: validation
Validate before calling
// Reject import paths whose first segment has no dot.
func looksLikeHostPath(p string) error {
host := p
if i := strings.Index(p, "/"); i >= 0 { host = p[:i] }
if !strings.Contains(host, ".") { return errors.New("path must begin with a hostname") }
return nil
} Type guard
null
Try / catch
null
Prevention
- Always use fully-qualified import paths (domain/repo[/sub]).
- Validate user-supplied module paths before go get.
When it happens
Trigger: `go get`/import of a path whose first segment has no dot, e.g. `go get foo` or `import "foo"`.
Common situations: Typos; forgotten domain prefix; trying to use a bare local name as a remote module.
Related errors
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/0436cd62bb29b2fd.
Report an issue: GitHub.