Documentation ¶
Overview ¶
Package urlinfo provides functions for extracting information out of url paths.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsSupportedVersion ¶
IsSupportedVersion reports whether the version is supported by the frontend.
func IsValidPath ¶
IsValidPath reports whether a requested path could be a valid unit.
Types ¶
type URLPathInfo ¶
type URLPathInfo struct { // FullPath is the full import path corresponding to the requested // package/module/directory page. FullPath string // ModulePath is the path of the module corresponding to the FullPath and // resolvedVersion. If unknown, it is set to internal.UnknownModulePath. ModulePath string // requestedVersion is the version requested by the user, which will be one // of the following: "latest", "master", a Go version tag, or a semantic // version. RequestedVersion string }
URLPathInfo contains the information about what unit is requested in a URL path.
func ExtractURLPathInfo ¶
func ExtractURLPathInfo(urlPath string) (_ *URLPathInfo, err error)
ExtractURLPathInfo extracts information from a request to pkg.go.dev. If an error is returned, the user will be served an http.StatusBadRequest.
func ParseDetailsURLPath ¶
func ParseDetailsURLPath(urlPath string) (_ *URLPathInfo, err error)
ParseDetailsURLPath parses a URL path that refers (or may refer) to something in the Go ecosystem.
After trimming leading and trailing slashes, the path is expected to have one of three forms, and we divide it into three parts: a full path, a module path, and a version.
The path has no '@', like github.com/hashicorp/vault/api. This is the full path. The module path is unknown. So is the version, so we treat it as the latest version for whatever the path denotes.
The path has "@version" at the end, like github.com/hashicorp/vault/api@v1.2.3. We split this at the '@' into a full path (github.com/hashicorp/vault/api) and version (v1.2.3); the module path is still unknown.
The path has "@version" in the middle, like github.com/hashicorp/vault@v1.2.3/api. (We call this the "canonical" form of a path.) We remove the version to get the full path, which is again github.com/hashicorp/vault/api. The version is v1.2.3, and the module path is the part before the '@', github.com/hashicorp/vault.
In one case, we do a little more than parse the urlPath into parts: if the full path could be a part of the standard library (because it has no '.'), we assume it is and set the ModulePath to indicate the standard library.