apidocs

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package apidocs is a shared fetcher for the GitLab API reference docs (the doc/api/<area>.md files in the gitlab-org/gitlab monorepo) used as a source of truth alongside the client-go SDK by the audit utilities.

Docs are cached on disk in a single shared, gitignored directory (.cache/gitlab-api-docs/ under the repo root). A cached doc is reused while it is younger than MaxAge (7 days by default); older or missing docs are re-downloaded. Callers can force a full refresh or pin to offline (cached only). Downloads are polite: a server Retry-After is honored, otherwise exponential backoff with jitter is used, and successful fetches are spaced so a full sweep does not trip GitLab's raw rate limiter.

Index

Constants

View Source
const (
	// DefaultBaseURL is the raw GitLab API reference doc root. Each area maps to
	// <DefaultBaseURL><area>.md.
	DefaultBaseURL = "https://gitlab.com/gitlab-org/gitlab/-/raw/master/doc/api/"

	// DefaultMaxAge is how long a cached doc is considered fresh before a
	// re-download is attempted.
	DefaultMaxAge = 7 * 24 * time.Hour
)

Variables

This section is empty.

Functions

func CacheDir

func CacheDir(repoRoot string) string

CacheDir returns the shared, gitignored API-doc cache directory for the given repository root.

Types

type Fetcher

type Fetcher struct {
	// contains filtered or unexported fields
}

Fetcher downloads and caches GitLab API reference docs. The zero value is not usable; construct one with New so defaults are applied.

func New

func New(repoRoot string, opts Options) *Fetcher

New returns a Fetcher writing to the shared cache under repoRoot.

func (*Fetcher) Fetch

func (f *Fetcher) Fetch(ctx context.Context, area string) (string, error)

Fetch returns the markdown for one doc area (e.g. "branches"). It serves a cached copy when present and fresh (younger than MaxAge) unless Refresh is set; otherwise it downloads, caches, and returns the doc. In Offline mode it returns the cached copy at any age and never downloads. The context cancels an in-flight download and aborts the retry backoff.

type Options

type Options struct {
	// Refresh forces a re-download even when the cached copy is still fresh.
	Refresh bool
	// Offline never hits the network: cached docs are returned regardless of
	// age, and a cache miss is an error.
	Offline bool
	// Strict disables the stale-cache fallback: when a download fails (e.g. an
	// upstream 404/410 removal), the error is returned instead of serving an
	// older cached copy. Authoritative callers such as -validate-docs set this
	// so a deleted doc is not masked by a previously cached body.
	Strict bool
	// MaxAge overrides the freshness window; 0 uses DefaultMaxAge.
	MaxAge time.Duration
	// BaseURL overrides the doc root (used by tests); empty uses DefaultBaseURL.
	BaseURL string
	// CacheDir overrides the on-disk cache location; empty uses the shared
	// CacheDir(repoRoot). Useful for tests and callers that want an isolated cache.
	CacheDir string
	// Client overrides the HTTP client; nil uses a 30s-timeout default.
	Client *http.Client
}

Options configures a Fetcher.

Jump to

Keyboard shortcuts

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