api

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2026 License: BSD-3-Clause Imports: 44 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OpenAPISpec []byte

OpenAPISpec contains the raw bytes of the OpenAPI 3.0 specification for the API.

Functions

func ParseParams

func ParseParams(v url.Values, dst any) error

ParseParams populates a struct from url.Values using 'form' tags. dst must be a pointer to a struct. It supports embedded structs recursively, pointers, slices, and basic types (string, bool, int types).

func ServeError

func ServeError(w http.ResponseWriter, r *http.Request, err error) error

func ServeModule

func ServeModule(w http.ResponseWriter, r *http.Request, ds internal.DataSource) (err error)

ServeModule handles requests for the v1beta module metadata endpoint. api:route /v1beta/module/{path} api:desc Information about the module at {path}. api:example /v1beta/module/golang.org/x/time

func ServeModulePackages

func ServeModulePackages(w http.ResponseWriter, r *http.Request, ds internal.DataSource) (err error)

ServeModulePackages handles requests for the v1beta module packages endpoint. api:route /v1beta/packages/{path} api:desc Information about packages of the module at {path}. api:desc Filtering is applied to the list of packages in the response. api:desc Only packages that match the filter query parameter are returned. api:example /v1beta/packages/golang.org/x/time/rate

func ServeModuleVersions

func ServeModuleVersions(w http.ResponseWriter, r *http.Request, ds internal.DataSource) (err error)

ServeModuleVersions handles requests for the v1beta module versions endpoint. api:route /v1beta/versions/{path} api:desc All versions of the module at {path}, including all major versions. api:desc Versions are listed in descending order, with incompatible versions last. api:desc Only tagged versions are returned, unless the pseudo query parameter is true. api:desc In addition, only results that match the filter query parameter are returned. api:desc The total in the response is -1 to indicate that the total number of results is unknown, api:desc unless all results fit on a single page. api:example /v1beta/versions/golang.org/x/time?limit=3

func ServePackage

func ServePackage(w http.ResponseWriter, r *http.Request, ds internal.DataSource) (err error)

ServePackage handles requests for the v1beta package metadata endpoint. api:route /v1beta/package/{path} api:desc Information about the package at {path}. api:example /v1beta/package/golang.org/x/time/rate

func ServePackageImportedBy

func ServePackageImportedBy(w http.ResponseWriter, r *http.Request, ds internal.DataSource) (err error)

ServePackageImportedBy handles requests for the v1beta package imported-by endpoint. api:route /v1beta/imported-by/{path} api:desc Paths of packages importing the package at {path}, api:desc not including packages in the same module. api:desc Filtering is applied to the list of paths in the response. api:desc Only paths that match the filter query parameter are returned. api:desc Within a filter, the variable `path` is set to the import path. api:example /v1beta/imported-by/golang.org/x/time/rate?limit=10&filter=%5E.%2A%5C.io%2F

func ServePackageSymbols

func ServePackageSymbols(w http.ResponseWriter, r *http.Request, ds internal.DataSource) (err error)

ServePackageSymbols handles requests for the v1beta package symbols endpoint. api:route /v1beta/symbols/{path} api:desc List of symbols for the package at {path}. api:desc Filtering is applied to the list of symbols in the response. api:desc Only symbols that match the filter query parameter are returned. api:example /v1beta/symbols/golang.org/x/time/rate

func ServeSearch

func ServeSearch(w http.ResponseWriter, r *http.Request, ds internal.DataSource) (err error)

ServeSearch handles requests for the v1 search endpoint. api:route /v1beta/search api:desc Search results. Only results that match the filter query parameter are returned. api:desc Results are sorted by how well the match the query, with the best match first. api:example /v1beta/search?q=xyzzy

func ServeVulnerabilities

func ServeVulnerabilities(vc *vuln.Client) func(w http.ResponseWriter, r *http.Request, _ internal.DataSource) error

ServeVulnerabilities handles requests for the v1beta vulnerabilities endpoint. api:route /v1beta/vulns/{path} api:desc Vulnerabilities of the module or package at {path}. api:desc Data comes from the Go vulnerability database (https://vuln.go.dev). api:desc Only results that match the filter query parameter are returned. api:example /v1beta/vulns/golang.org/x/image

Types

type Candidate

type Candidate struct {
	ModulePath  string `json:"modulePath"`
	PackagePath string `json:"packagePath"`
}

A Candidate is a potential resolution for an ambiguous path.

type Error

type Error struct {
	// Code is the HTTP status code.
	Code    int    `json:"code"`
	Message string `json:"message"`
	// Fixes are suggestions for how to fix.
	Fixes      []string    `json:"fixes"`
	Candidates []Candidate `json:"candidates,omitempty"`
	// contains filtered or unexported fields
}

Error contains detailed information about an error.

func BadRequest

func BadRequest(msg string, fixes ...string) *Error

BadRequest returns an Error with StatusBadRequest.

func InternalServerError

func InternalServerError(format string, args ...any) *Error

InternalServerError returns an Error with StatusInternalServerError.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Example

type Example struct {
	Request  string
	Response string
}

Example contains an API request example (URL path) and its expected response.

type ImportedByParams

type ImportedByParams struct {
	// Module path.
	Module string `form:"module"`
	// Module version: semantic version, 'latest', or default branches 'master' or 'main'.
	// (Latest if empty).
	Version string `form:"version"`
	ListParams
}

ImportedByParams are query parameters for /v1beta/imported-by/{path}.

type License

type License struct {
	Types    []string `json:"types"`
	FilePath string   `json:"filePath"`
	Contents string   `json:"contents,omitempty"`
}

License is license information in API responses.

type ListParams

type ListParams struct {
	// Max number of items to return.
	Limit int `form:"limit"`
	// Where to resume listing.
	Token string `form:"token"`
	// Include only items matching the regular expression filter.
	Filter string `form:"filter"`
}

ListParams are common pagination and filtering parameters.

type Module

type Module struct {
	Path    string `json:"path"`
	Version string `json:"version"`
	// CommitTime is the timestamp returned by the module proxy's .info endpoint,
	// representing the time the version was created.
	CommitTime        time.Time `json:"commitTime"`
	IsLatest          bool      `json:"isLatest"`
	IsRedistributable bool      `json:"isRedistributable"`
	IsStandardLibrary bool      `json:"isStandardLibrary"`
	HasGoMod          bool      `json:"hasGoMod"`
	RepoURL           string    `json:"repoUrl"`
	GoModContents     string    `json:"goModContents,omitempty"`
	Readme            *Readme   `json:"readme,omitempty"`
	Licenses          []License `json:"licenses,omitempty"`
}

Module is the response for /v1beta/module/{modulePath}.

type ModuleParams

type ModuleParams struct {
	// Module version: semantic version, 'latest', or default branches 'master' or 'main'.
	// (Latest if empty).
	Version string `form:"version"`
	// Whether to include licenses in the result.
	Licenses bool `form:"licenses"`
	// Whether to include the README in the result.
	Readme bool `form:"readme"`
}

ModuleParams are query parameters for /v1beta/module/{path}.

type ModuleVersion

type ModuleVersion struct {
	ModulePath string    `json:"modulePath"`
	Version    string    `json:"version"`
	CommitTime time.Time `json:"commitTime"`
	// IsRedistributable is whether the license allows distribution.
	IsRedistributable bool `json:"isRedistributable"`
	// HasGoMod is whether the module has a go.mod file.
	HasGoMod bool `json:"hasGoMod"`
	// LatestVersion is the latest unretracted version.
	LatestVersion     string `json:"latestVersion"`
	Deprecated        bool   `json:"deprecated"`
	DeprecationReason string `json:"deprecationReason"`
	Retracted         bool   `json:"retracted"`
	RetractionReason  string `json:"retractionReason"`
}

ModuleVersion is the response for /v1beta/versions/{path}.

type Package

type Package struct {
	ModulePath        string    `json:"modulePath"`
	Version           string    `json:"version"`
	IsLatest          bool      `json:"isLatest"`
	IsStandardLibrary bool      `json:"isStandardLibrary"`
	GOOS              string    `json:"goos"`
	GOARCH            string    `json:"goarch"`
	Docs              string    `json:"docs,omitempty"`
	Imports           []string  `json:"imports,omitempty"`
	Licenses          []License `json:"licenses,omitempty"`
	PackageInfo
}

Package is the response for /v1beta/package/{packagePath}.

type PackageImportedBy

type PackageImportedBy struct {
	ModulePath string                    `json:"modulePath"`
	Version    string                    `json:"version"`
	ImportedBy PaginatedResponse[string] `json:"importedBy"`
}

PackageImportedBy is the response for /v1beta/imported-by/{packagePath}.

type PackageInfo

type PackageInfo struct {
	Path     string `json:"path"`
	Name     string `json:"name"`
	Synopsis string `json:"synopsis"`
	// IsRedistributable is whether the license allows distribution.
	IsRedistributable bool `json:"isRedistributable"`
}

type PackageParams

type PackageParams struct {
	// Module path.
	Module string `form:"module"`
	// Module version: semantic version, 'latest', or default branches 'master' or 'main'.
	// (Latest if empty).
	Version string `form:"version"`
	// GOOS of documentation build context.
	GOOS string `form:"goos"`
	// GOARCH of documentation build context.
	GOARCH string `form:"goarch"`
	// Documentation format: text, html, md or markdown.
	// If omitted, documentation is not returned.
	Doc string `form:"doc"`
	// Whether to include examples with the returned documentation.
	Examples bool `form:"examples"`
	// Whether to include the packages that this one imports.
	Imports bool `form:"imports"`
	// Whether to include licenses in the result.
	Licenses bool `form:"licenses"`
}

PackageParams are query parameters for /v1beta/package/{path}.

type PackageSymbols

type PackageSymbols struct {
	ModulePath string                    `json:"modulePath"`
	Version    string                    `json:"version"`
	Symbols    PaginatedResponse[Symbol] `json:"symbols"`
}

PackageSymbols is the response for /v1beta/symbols/{packagePath}.

type PackagesParams

type PackagesParams struct {
	// Module version: semantic version, 'latest', or default branches 'master' or 'main'.
	// (Latest if empty).
	Version string `form:"version"`
	ListParams
}

PackagesParams are query parameters for /v1beta/packages/{path}.

type PackagesResponse

type PackagesResponse struct {
	ModulePath        string                         `json:"modulePath"`
	Version           string                         `json:"version"`
	IsStandardLibrary bool                           `json:"isStandardLibrary"`
	Packages          PaginatedResponse[PackageInfo] `json:"packages"`
}

type PaginatedResponse

type PaginatedResponse[T any] struct {
	Items         []T    `json:"items"`
	Total         int    `json:"total"`
	NextPageToken string `json:"nextPageToken,omitempty"`
}

PaginatedResponse is a generic paginated response.

type PathParam added in v0.3.0

type PathParam struct {
	Name string
	Doc  string
}

PathParam contains information about a path parameter.

type QueryParam

type QueryParam struct {
	Name string
	Type string
	Doc  string
}

QueryParam contains information about a query parameter.

type Readme

type Readme struct {
	Filepath string `json:"filepath"`
	Contents string `json:"contents"`
}

Readme is a readme file.

type RouteInfo

type RouteInfo struct {
	Route                 string
	Tags                  []string
	Summary               string
	Desc                  string
	Params                string
	Response              string
	ResponsePaginatedType string
	LinkPaginatedType     bool
	PathParams            []PathParam
	QueryParams           []QueryParam
	Examples              []*Example
}

RouteInfo contains documentation information for an API route.

func RouteInfos

func RouteInfos(ctx context.Context, baseURL string) ([]*RouteInfo, error)

RouteInfos returns the documentation information for all routes, and executes examples against the given baseURL if they haven't been executed yet.

type SearchParams

type SearchParams struct {
	// Find packages matching this query.
	Query string `form:"q"`
	// If non-empty, find symbols matching this string.
	// The query further restricts the search to matching packages.
	Symbol string `form:"symbol"`
	ListParams
}

SearchParams are query parameters for /v1beta/search.

type SearchResult

type SearchResult struct {
	PackagePath string `json:"packagePath"`
	ModulePath  string `json:"modulePath"`
	Version     string `json:"version"`
	Synopsis    string `json:"synopsis"`
}

SearchResults is the response for /v1beta/search?q={query}.

type Symbol

type Symbol struct {
	Name string `json:"name"`
	// Kind is one of "Constant", "Variable", "Function", "Type", "Field", or "Method".
	Kind     string `json:"kind"`
	Synopsis string `json:"synopsis"`
	Parent   string `json:"parent,omitempty"`
}

Symbol is a symbol in a package.

type SymbolsParams

type SymbolsParams struct {
	// Module path.
	Module string `form:"module"`
	// Module version: semantic version, 'latest', or default branches 'master' or 'main'.
	// (Latest if empty).
	Version string `form:"version"`
	// GOOS of documentation build context.
	GOOS string `form:"goos"`
	// GOARCH of documentation build context.
	GOARCH string `form:"goarch"`
	ListParams
}

SymbolsParams are query parameters for /v1beta/symbols/{path}.

type VersionsParams

type VersionsParams struct {
	ListParams
	// Whether to include pseudo-versions in the result.
	PseudoVersions bool `form:"pseudo"`
}

VersionsParams are query parameters for /v1beta/versions/{path}.

type VulnParams

type VulnParams struct {
	// Module path.
	Module string `form:"module"`
	// Module version: semantic version, 'latest', or default branches 'master' or 'main'.
	// (Latest if empty).
	Version string `form:"version"`
	ListParams
}

VulnParams are query parameters for /v1beta/vulns/{path}.

type Vulnerability

type Vulnerability struct {
	ID           string `json:"id"`
	Summary      string `json:"summary"`
	Details      string `json:"details"`
	FixedVersion string `json:"fixedVersion"`
}

Vulnerability is a vulnerability in /v1beta/vulnerabilities/{modulePath}.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL