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) 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 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 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 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 ErrProxyDisabled = errors.New("pkggodev: no usable module proxy (GOPROXY)")
ErrProxyDisabled is returned by MajorVersions 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) 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 Example ΒΆ added in v0.2.0
type Example struct {
Name string `json:"name,omitempty"` // Suffix of "Example (name)", empty for a bare "Example".
Code string `json:"code"`
Output string `json:"output,omitempty"`
}
Example is a runnable example attached to a symbol.
type ImportedByResult ΒΆ
type ImportedByResult struct {
ModulePath string `json:"modulePath,omitempty"`
Version string `json:"version,omitempty"`
Packages Page[string] `json:"packages"`
}
ImportedByResult lists the packages that import a given package.
type License ΒΆ
type License struct {
Contents string `json:"contents,omitempty"`
FilePath string `json:"filePath,omitempty"`
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 string `json:"version,omitempty"`
RepoURL string `json:"repoUrl,omitempty"`
GoModContents string `json:"goModContents,omitempty"`
CommitTime time.Time `json:"commitTime,omitzero"`
HasGoMod bool `json:"hasGoMod"`
IsLatest bool `json:"isLatest"`
IsRedistributable bool `json:"isRedistributable"`
IsStandardLibrary bool `json:"isStandardLibrary"`
Licenses []License `json:"licenses,omitempty"`
Readme 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"`
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 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 string `json:"modulePath,omitempty"`
Name string `json:"name,omitempty"`
Synopsis string `json:"synopsis,omitempty"`
Version string `json:"version,omitempty"`
Goos string `json:"goos,omitempty"`
Goarch string `json:"goarch,omitempty"`
Docs string `json:"docs,omitempty"`
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 string `json:"modulePath,omitempty"`
Version string `json:"version,omitempty"`
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 string `json:"nextToken,omitempty"` Total int `json:"total"` }
Page is a paginated slice of T returned by listing endpoints.
type Readme ΒΆ
type Readme struct {
Contents string `json:"contents,omitempty"`
Filepath string `json:"filepath,omitempty"`
}
Readme is a module README.
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 string `json:"synopsis,omitempty"`
Doc string `json:"doc,omitempty"`
Examples []Example `json:"examples,omitempty"` // Populated only when WithExamples is set.
Version string `json:"version,omitempty"`
Goos string `json:"goos,omitempty"`
Goarch string `json:"goarch,omitempty"`
}
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). |
|
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). |