Documentation
ΒΆ
Overview ΒΆ
Package pkggodev is a typed Go client for the pkg.go.dev API.
It wraps the ogen-generated client (under internal/api) with an ergonomic, context-first surface and clean response types.
Index ΒΆ
- Constants
- Variables
- type Client
- func (c *Client) AllImportedBy(ctx context.Context, path string, opts ...Option) iter.Seq2[string, error]
- func (c *Client) AllPackages(ctx context.Context, path string, opts ...Option) iter.Seq2[PackageInfo, error]
- func (c *Client) AllSearch(ctx context.Context, opts ...Option) iter.Seq2[SearchResult, error]
- func (c *Client) AllSymbols(ctx context.Context, path string, opts ...Option) iter.Seq2[SymbolInfo, error]
- func (c *Client) AllVersions(ctx context.Context, path string, opts ...Option) iter.Seq2[ModuleVersion, error]
- func (c *Client) AllVulns(ctx context.Context, path string, opts ...Option) iter.Seq2[Vulnerability, error]
- func (c *Client) Dependencies(ctx context.Context, modulePath string, opts ...Option) (*DependenciesResult, error)
- func (c *Client) ImportedBy(ctx context.Context, path string, opts ...Option) (*ImportedByResult, error)
- func (c *Client) MajorVersions(ctx context.Context, modulePath string, opts ...Option) (*Page[MajorVersion], error)
- func (c *Client) Module(ctx context.Context, path string, opts ...Option) (*Module, error)
- func (c *Client) Package(ctx context.Context, path string, opts ...Option) (*Package, error)
- func (c *Client) Packages(ctx context.Context, path string, opts ...Option) (*PackagesResult, error)
- func (c *Client) Search(ctx context.Context, opts ...Option) (*Page[SearchResult], error)
- func (c *Client) Symbol(ctx context.Context, path, symbol string, opts ...Option) (*Symbol, error)
- func (c *Client) Symbols(ctx context.Context, path string, opts ...Option) (*Page[SymbolInfo], error)
- func (c *Client) Versions(ctx context.Context, path string, opts ...Option) (*Page[ModuleVersion], error)
- func (c *Client) Vulns(ctx context.Context, path string, opts ...Option) (*Page[Vulnerability], error)
- type ClientOption
- type DependenciesResult
- type Dependency
- type Example
- type ImportedByResult
- type License
- type MajorVersion
- type Module
- type ModuleVersion
- type Option
- func WithDoc(s string) Option
- func WithExamples() Option
- func WithExcludePseudo() Option
- func WithFilter(f string) Option
- func WithGOARCH(s string) Option
- func WithGOOS(s string) Option
- func WithImports() Option
- func WithLicenses() Option
- func WithLimit(n int) Option
- func WithModule(m string) Option
- func WithQuery(q string) Option
- func WithReadme() Option
- func WithSize() Option
- func WithSymbol(s string) Option
- func WithToken(t string) Option
- func WithVersion(v string) Option
- type Package
- type PackageInfo
- type PackagesResult
- type Page
- type Readme
- type Replacement
- type SearchResult
- type Symbol
- type SymbolInfo
- type Vulnerability
Constants ΒΆ
const DefaultBaseURL = api.DefaultBaseURL
DefaultBaseURL is the production pkg.go.dev API base URL.
const DefaultMaxIdleConns = 1000
DefaultMaxIdleConns is the number of idle keep-alive connections the default HTTP client keeps open for reuse, shared across the API and proxy calls. The standard http.DefaultTransport keeps only 2 idle connections per host, which throttles the highly concurrent calls this client is built for.
Variables ΒΆ
var ErrInvalidModulePath = errors.New("pkggodev: invalid module path")
ErrInvalidModulePath is returned when a module path cannot be parsed, e.g. by MajorVersions.
var ErrModuleNotFound = errors.New("pkggodev: module not found")
ErrModuleNotFound is returned by Dependencies when the module (at the requested version) is unknown to every configured proxy.
var ErrProxyDisabled = errors.New("pkggodev: no usable module proxy (GOPROXY)")
ErrProxyDisabled is returned by MajorVersions and Dependencies (and by Module/ Versions when WithSize is set) when no usable module proxy is configured (GOPROXY is "off" or resolves to "direct" only).
var ErrSymbolNotFound = errors.New("pkggodev: symbol not found")
ErrSymbolNotFound is returned by Client.Symbol when the requested symbol is absent from the package documentation.
Functions ΒΆ
This section is empty.
Types ΒΆ
type Client ΒΆ
type Client struct {
// contains filtered or unexported fields
}
Client is the pkg.go.dev API api.
func New ΒΆ
func New(opts ...ClientOption) (*Client, error)
New builds a pkg.go.dev client with sane defaults.
func (*Client) AllImportedBy ΒΆ
func (c *Client) AllImportedBy(ctx context.Context, path string, opts ...Option) iter.Seq2[string, error]
AllImportedBy iterates all packages that import the package at path.
func (*Client) AllPackages ΒΆ
func (c *Client) AllPackages(ctx context.Context, path string, opts ...Option) iter.Seq2[PackageInfo, error]
AllPackages iterates all packages contained in the module at path.
func (*Client) AllSymbols ΒΆ
func (c *Client) AllSymbols(ctx context.Context, path string, opts ...Option) iter.Seq2[SymbolInfo, error]
AllSymbols iterates all exported symbols of the package at path.
func (*Client) AllVersions ΒΆ
func (c *Client) AllVersions(ctx context.Context, path string, opts ...Option) iter.Seq2[ModuleVersion, error]
AllVersions iterates all versions of the module at path, fetching pages lazily.
func (*Client) AllVulns ΒΆ
func (c *Client) AllVulns(ctx context.Context, path string, opts ...Option) iter.Seq2[Vulnerability, error]
AllVulns iterates all vulnerabilities for the module or package at path.
func (*Client) Dependencies ΒΆ added in v0.4.0
func (c *Client) Dependencies(ctx context.Context, modulePath string, opts ...Option) (*DependenciesResult, error)
Dependencies returns the dependencies declared in the go.mod of the module at modulePath, parsed from the Go module proxy (honoring GOPROXY, see WithGoproxy). It reports the require directives β each with its version and whether it is "// indirect" β plus any replace and exclude directives and the module's go directive.
WithVersion selects the version; when unset (or "latest") the proxy's latest version is used, and the result's Version is the concrete version the go.mod was read at. Dependencies returns ErrProxyDisabled when GOPROXY is "off"/"direct"-only, ErrInvalidModulePath for an unparsable path, and ErrModuleNotFound when the module version is unknown to every proxy.
func (*Client) ImportedBy ΒΆ
func (c *Client) ImportedBy(ctx context.Context, path string, opts ...Option) (*ImportedByResult, error)
ImportedBy lists the packages that import the package at path.
func (*Client) MajorVersions ΒΆ added in v0.2.0
func (c *Client) MajorVersions(ctx context.Context, modulePath string, opts ...Option) (*Page[MajorVersion], error)
MajorVersions discovers the major versions of the module at modulePath.
In Go, majors beyond v1 live as separate modules (path, path/v2, path/v3...) and can be non-contiguous. pkg.go.dev does not (yet) expose a MajorVersions endpoint (golang/go#76718), so this derives the answer from the module proxy (honoring GOPROXY, see WithGoproxy). modulePath may already carry a major suffix (path/v2 or gopkg.in/pkg.v2); it is normalized to the base path first.
WithExcludePseudo drops majors whose latest version is a pseudo-version. WithFilter applies a regular expression to each major's module path. WithLimit caps the number of returned majors (the proposal's Max), keeping the most recent ones. The module proxy has no pagination cursor, so the result is always a single page (NextToken is empty); Total is the count before WithLimit.
func (*Client) Packages ΒΆ
func (c *Client) Packages(ctx context.Context, path string, opts ...Option) (*PackagesResult, error)
Packages lists the packages contained in the module at path.
func (*Client) Symbol ΒΆ added in v0.2.0
Symbol returns the full documentation of a single symbol of the package at path. symbol is the exported identifier (e.g. "Map") or "Type.Method" (e.g. "Either.ForEach"); matching is case-sensitive. WithExamples includes runnable examples.
The documentation is derived client-side from the package documentation, which is always requested in Markdown form, so WithDoc has no effect here. It returns ErrSymbolNotFound when the symbol is absent from the package.
func (*Client) Symbols ΒΆ
func (c *Client) Symbols(ctx context.Context, path string, opts ...Option) (*Page[SymbolInfo], error)
Symbols lists the exported symbols of the package at path.
type ClientOption ΒΆ
type ClientOption func(*clientConfig)
ClientOption configures the Client built by New.
func WithGoproxy ΒΆ added in v0.2.0
func WithGoproxy(s string) ClientOption
WithGoproxy overrides the module proxy list used by MajorVersions. The value uses the same syntax as the GOPROXY environment variable (a "," or "|" separated list of base URLs, plus the keywords "direct" and "off"). When unset, the client honors the GOPROXY environment variable, defaulting to https://proxy.golang.org.
func WithHTTPClient ΒΆ
func WithHTTPClient(h *http.Client) ClientOption
WithHTTPClient sets a custom *http.Client (timeouts, transport, etc.).
func WithUserAgent ΒΆ
func WithUserAgent(ua string) ClientOption
WithUserAgent sets the User-Agent header sent on every request.
type DependenciesResult ΒΆ added in v0.4.0
type DependenciesResult struct {
ModulePath string `json:"modulePath"`
Version string `json:"version"` // the concrete version the go.mod was read at.
GoVersion mo.Option[string] `json:"goVersion,omitzero"` // the "go" directive, e.g. "1.25".
Requires []Dependency `json:"requires,omitempty"`
Replaces []Replacement `json:"replaces,omitempty"`
Excludes []Dependency `json:"excludes,omitempty"`
}
DependenciesResult is the parsed go.mod of a module: the dependencies it declares (requires), plus any replace/exclude directives, fetched from the Go module proxy. See Client.Dependencies.
type Dependency ΒΆ added in v0.4.0
type Dependency struct {
Path string `json:"path"`
Version mo.Option[string] `json:"version,omitzero"`
Indirect bool `json:"indirect,omitempty"` // true for a "// indirect" require (transitive, not imported directly).
}
Dependency is one module a target module depends on, parsed from a go.mod require (or exclude) directive.
type Example ΒΆ added in v0.2.0
type Example struct {
Name mo.Option[string] `json:"name,omitzero"` // Suffix of "Example (name)", absent for a bare "Example".
Code string `json:"code"`
Output mo.Option[string] `json:"output,omitzero"`
}
Example is a runnable example attached to a symbol.
type ImportedByResult ΒΆ
type ImportedByResult struct {
ModulePath mo.Option[string] `json:"modulePath,omitzero"`
Version mo.Option[string] `json:"version,omitzero"`
Packages Page[string] `json:"packages"`
}
ImportedByResult lists the packages that import a given package.
type License ΒΆ
type License struct {
Contents mo.Option[string] `json:"contents,omitzero"`
FilePath mo.Option[string] `json:"filePath,omitzero"`
Types []string `json:"types,omitempty"`
}
License describes a license file detected in a module or package.
type MajorVersion ΒΆ added in v0.2.0
type MajorVersion struct {
ModulePath string `json:"modulePath"` // e.g. "github.com/samber/do/v2"
Major string `json:"major"` // e.g. "v2"
Version string `json:"version"` // latest version in this major, e.g. "v2.0.0"
IsLatest bool `json:"isLatest"` // true for the highest major
}
MajorVersion is one major version of a module, discovered via the module proxy (see Client.MajorVersions). Majors beyond v1 live as separate modules (path, path/v2, path/v3...), so each MajorVersion carries its own module path.
type Module ΒΆ
type Module struct {
Path string `json:"path"`
Version mo.Option[string] `json:"version,omitzero"`
GoVersion mo.Option[string] `json:"goVersion,omitzero"` // the "go" directive of go.mod, e.g. "1.25".
RepoURL mo.Option[string] `json:"repoUrl,omitzero"`
GoModContents mo.Option[string] `json:"goModContents,omitzero"`
CommitTime mo.Option[time.Time] `json:"commitTime,omitzero"`
Size mo.Option[int64] `json:"size,omitzero"` // module zip size in bytes; present only with WithSize.
HasGoMod bool `json:"hasGoMod"`
IsLatest bool `json:"isLatest"`
IsRedistributable bool `json:"isRedistributable"`
IsStandardLibrary bool `json:"isStandardLibrary"`
Licenses []License `json:"licenses,omitempty"`
Readme mo.Option[Readme] `json:"readme,omitzero"`
}
Module is metadata about a single module.
type ModuleVersion ΒΆ
type ModuleVersion struct {
ModulePath string `json:"modulePath"`
Version string `json:"version"`
LatestVersion string `json:"latestVersion"`
CommitTime time.Time `json:"commitTime"`
Size mo.Option[int64] `json:"size,omitzero"` // version zip size in bytes; present only with WithSize.
HasGoMod bool `json:"hasGoMod"`
IsRedistributable bool `json:"isRedistributable"`
Deprecated bool `json:"deprecated"`
DeprecationReason string `json:"deprecationReason"`
Retracted bool `json:"retracted"`
RetractionReason string `json:"retractionReason"`
}
ModuleVersion is one entry from a /versions response.
type Option ΒΆ
type Option func(*params)
Option configures optional query parameters for a single API call. Each method ignores options that do not apply to it.
func WithExamples ΒΆ
func WithExamples() Option
WithExamples includes examples with returned documentation.
func WithExcludePseudo ΒΆ added in v0.2.0
func WithExcludePseudo() Option
WithExcludePseudo drops majors whose latest version is a pseudo-version (untagged commits). It reflects the ExcludePseudo flag of the proposed pkg.go.dev MajorVersions endpoint (golang/go#76718) and applies to MajorVersions only.
func WithFilter ΒΆ
WithFilter applies a regular-expression filter to listing results.
func WithGOARCH ΒΆ
WithGOARCH sets the GOARCH documentation build context.
func WithImports ΒΆ
func WithImports() Option
WithImports includes the list of packages the target imports.
func WithModule ΒΆ
WithModule sets the module path for package-scoped calls.
func WithReadme ΒΆ
func WithReadme() Option
WithReadme includes the README in the result (Module only).
func WithSize ΒΆ added in v0.4.0
func WithSize() Option
WithSize includes module download sizes in the result. A size is the Content-Length of the module zip on the Go module proxy (see WithGoproxy), fetched with a HEAD request. It applies to Module (Module.Size, one extra request) and Versions (ModuleVersion.Size, one concurrent request per listed version). Both return ErrProxyDisabled when WithSize is set but GOPROXY is "off"/"direct"-only.
func WithSymbol ΒΆ
WithSymbol sets the symbol search query (Search only).
func WithVersion ΒΆ
WithVersion selects a module version (semver, "latest", "master" or "main").
type Package ΒΆ
type Package struct {
Path string `json:"path"`
ModulePath mo.Option[string] `json:"modulePath,omitzero"`
Name mo.Option[string] `json:"name,omitzero"`
Synopsis mo.Option[string] `json:"synopsis,omitzero"`
Version mo.Option[string] `json:"version,omitzero"`
Goos mo.Option[string] `json:"goos,omitzero"`
Goarch mo.Option[string] `json:"goarch,omitzero"`
Docs mo.Option[string] `json:"docs,omitzero"`
Imports []string `json:"imports,omitempty"`
IsLatest bool `json:"isLatest"`
IsRedistributable bool `json:"isRedistributable"`
IsStandardLibrary bool `json:"isStandardLibrary"`
Licenses []License `json:"licenses,omitempty"`
}
Package is documentation and metadata about a single package.
type PackageInfo ΒΆ
type PackageInfo struct {
Path string `json:"path"`
Name string `json:"name"`
Synopsis string `json:"synopsis"`
IsRedistributable bool `json:"isRedistributable"`
}
PackageInfo is one entry from a /packages response.
type PackagesResult ΒΆ
type PackagesResult struct {
ModulePath mo.Option[string] `json:"modulePath,omitzero"`
Version mo.Option[string] `json:"version,omitzero"`
IsStandardLibrary bool `json:"isStandardLibrary"`
Packages Page[PackageInfo] `json:"packages"`
}
PackagesResult lists the packages contained in a module.
type Page ΒΆ
type Page[T any] struct { Items []T `json:"items"` NextToken mo.Option[string] `json:"nextToken,omitzero"` Total int `json:"total"` }
Page is a paginated slice of T returned by listing endpoints.
type Readme ΒΆ
type Readme struct {
Contents mo.Option[string] `json:"contents,omitzero"`
Filepath mo.Option[string] `json:"filepath,omitzero"`
}
Readme is a module README.
type Replacement ΒΆ added in v0.4.0
type Replacement struct {
OldPath string `json:"oldPath"`
OldVersion mo.Option[string] `json:"oldVersion,omitzero"`
NewPath string `json:"newPath"`
NewVersion mo.Option[string] `json:"newVersion,omitzero"`
}
Replacement is one go.mod replace directive, redirecting a module (optionally pinned to OldVersion) to NewPath. A NewPath that is a filesystem path with no NewVersion is a local replacement.
type SearchResult ΒΆ
type SearchResult struct {
ModulePath string `json:"modulePath"`
PackagePath string `json:"packagePath"`
Synopsis string `json:"synopsis"`
Version string `json:"version"`
}
SearchResult is one entry from a /search response.
type Symbol ΒΆ
type Symbol struct {
Path string `json:"path"`
Name string `json:"name"`
Kind string `json:"kind"` // Function, Method, Type, Variable or Constant.
Signature string `json:"signature"`
Synopsis mo.Option[string] `json:"synopsis,omitzero"`
Doc mo.Option[string] `json:"doc,omitzero"`
Examples []Example `json:"examples,omitempty"` // Populated only when WithExamples is set.
Version mo.Option[string] `json:"version,omitzero"`
Goos mo.Option[string] `json:"goos,omitzero"`
Goarch mo.Option[string] `json:"goarch,omitzero"`
}
Symbol is the full documentation of a single package symbol, derived client-side from the package documentation. See Client.Symbol.
type SymbolInfo ΒΆ added in v0.2.0
type SymbolInfo struct {
Name string `json:"name"`
Kind string `json:"kind"`
Synopsis string `json:"synopsis"`
Parent string `json:"parent"`
}
SymbolInfo is one entry from a /symbols response: lightweight metadata about a package symbol. Use Client.Symbol to fetch the full documentation of one symbol.
Directories
ΒΆ
| Path | Synopsis |
|---|---|
|
internal
|
|
|
api
Package api is the ogen-generated pkg.go.dev API client.
|
Package api is the ogen-generated pkg.go.dev API client. |
|
godoc
Package godoc derives the documentation of a single symbol from the package documentation returned by pkg.go.dev in Markdown form (doc=markdown).
|
Package godoc derives the documentation of a single symbol from the package documentation returned by pkg.go.dev in Markdown form (doc=markdown). |
|
gomod
Package gomod parses the go.mod file of a module (as served by the Go module proxy) into a neutral structure: its Go version, requirements, replacements and exclusions.
|
Package gomod parses the go.mod file of a module (as served by the Go module proxy) into a neutral structure: its Go version, requirements, replacements and exclusions. |
|
majors
Package majors discovers the major versions of a Go module from the module proxy.
|
Package majors discovers the major versions of a Go module from the module proxy. |
|
proxy
Package proxy is a minimal Go module proxy client (https://go.dev/ref/mod#goproxy-protocol).
|
Package proxy is a minimal Go module proxy client (https://go.dev/ref/mod#goproxy-protocol). |