docs

package
v1.45.2 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package docs provides an HTTP client for interacting with docs.stripe.com. It supports fetching documentation pages, searching, and browsing content with built-in filesystem caching and configurable TTL-based eviction.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Get(key string) (data []byte, cachedAt time.Time, ok bool, err error)
	Set(key string, data []byte) error
}

Cache defines the interface for storing and retrieving page content.

type CacheOption

type CacheOption func(*FSCache)

CacheOption configures an FSCache.

func WithClock

func WithClock(now func() time.Time) CacheOption

WithClock overrides the time source used for TTL checks.

func WithFS

func WithFS(fs afero.Fs) CacheOption

WithFS sets the filesystem implementation. Defaults to the real OS filesystem.

func WithTTL

func WithTTL(ttl time.Duration) CacheOption

WithTTL sets the cache entry time-to-live. Defaults to 1 hour.

type Client

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

Client fetches documentation pages and calls endpoints on docs.stripe.com.

func NewClient

func NewClient(_ string) *Client

NewClient creates a Client configured to talk to docs.stripe.com.

func (*Client) FetchPage

func (c *Client) FetchPage(ctx context.Context, ref *url.URL) (Page, error)

FetchPage retrieves a documentation page as plain text, using cache when available.

page, err := c.FetchPage(ctx, &url.URL{Path: "/payments/accept-a-payment", RawQuery: "api_version=2024-06-30"})

func (*Client) FetchPrefs added in v1.44.1

func (c *Client) FetchPrefs(ctx context.Context) (*PrefsResponse, error)

FetchPrefs retrieves the list of documentation preferences from docs.stripe.com.

func (*Client) Search

func (c *Client) Search(ctx context.Context, query string) (*SearchResponse, error)

Search sends the request to docs search endpoint and returns a list of search results.

response, err := c.Search(ctx, "payment methods")

func (*Client) WithOptions

func (c *Client) WithOptions(opts ...ClientOption) *Client

WithOptions applies the given options and returns the Client for chaining.

type ClientOption

type ClientOption func(*Client)

ClientOption configures a Client.

func WithAPIBaseURL added in v1.45.2

func WithAPIBaseURL(u string) ClientOption

WithAPIBaseURL overrides the Stripe API base URL used for authenticated requests (defaults to https://api.stripe.com).

func WithAPIKey added in v1.44.1

func WithAPIKey(key string) ClientOption

WithAPIKey sets the Stripe API key sent as an Authorization header on every request.

func WithBaseURL

func WithBaseURL(u string) ClientOption

WithBaseURL overrides the default docs.stripe.com base URL.

func WithCache

func WithCache(cache Cache) ClientOption

WithCache enables response caching for FetchPage.

func WithCacheKeyPrefix added in v1.44.1

func WithCacheKeyPrefix(prefix string) ClientOption

WithCacheKeyPrefix scopes the FetchPage cache to a specific account by prefixing all cache keys with prefix. Pass the account ID (e.g. "acct_xxx") so that cached entries from one account are never served to another. An empty prefix is a no-op, which keeps unauthenticated usage working without changes.

func WithHTTPClient

func WithHTTPClient(hc *http.Client) ClientOption

WithHTTPClient sets a custom http.Client.

func WithLogger

func WithLogger(logger *log.Entry) ClientOption

WithLogger sets a custom logger.

func WithPrefs added in v1.44.1

func WithPrefs(prefs map[string]string) ClientOption

WithPrefs sets documentation preferences to include as query parameters on page fetches. A preference is only applied when the fetched URL does not already carry that parameter.

type FSCache

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

FSCache implements Cache using the local filesystem with a TTL-based eviction policy. Entries older than the configured TTL are treated as misses and removed on access.

func NewFSCache

func NewFSCache(dir string, opts ...CacheOption) (*FSCache, error)

NewFSCache creates a filesystem-backed cache rooted at dir.

func (*FSCache) Get

func (c *FSCache) Get(key string) ([]byte, time.Time, bool, error)

Get retrieves a cached entry by key, returning the data, cache time, and whether the entry was found. Expired entries are removed on access.

func (*FSCache) Set

func (c *FSCache) Set(key string, data []byte) error

Set writes data to the cache under key.

type Hit

type Hit struct {
	Title string `json:"title"`
	URL   string `json:"url"`
}

Hit represents a single search hit from docs.stripe.com.

type Page

type Page struct {
	// Content is the raw page body returned by docs.stripe.com.
	Content []byte
	// URL is the fully resolved URL including query parameters.
	URL *url.URL
	// FetchedAt is when the content was originally retrieved from docs.stripe.com.
	FetchedAt time.Time
}

Page holds the content and metadata of a fetched documentation page.

type Pref added in v1.44.1

type Pref struct {
	ID          string   `json:"id"`
	Category    *string  `json:"category"`
	Description string   `json:"description"`
	Values      []string `json:"values"`
	Default     *string  `json:"default"`
}

Pref represents a single documentation preference.

type PrefsResponse added in v1.44.1

type PrefsResponse struct {
	Prefs []Pref `json:"prefs"`
}

PrefsResponse represents the response from the docs prefs endpoint.

type SearchResponse

type SearchResponse struct {
	Hits []Hit
}

SearchResponse represents the response from the docs search endpoint.

Directories

Path Synopsis
Package markdown provides markdown parsing and terminal rendering capabilities.
Package markdown provides markdown parsing and terminal rendering capabilities.
Package pager provides a writer that pipes output through a terminal pager (respecting $PAGER, defaulting to less) when stdout is a TTY.
Package pager provides a writer that pipes output through a terminal pager (respecting $PAGER, defaulting to less) when stdout is a TTY.
Package palette provides a command-palette bubble for Bubble Tea programs.
Package palette provides a command-palette bubble for Bubble Tea programs.
Package spinner provides a simple terminal spinner backed by Bubble Tea.
Package spinner provides a simple terminal spinner backed by Bubble Tea.
Package tui provides a Bubble Tea TUI for browsing Stripe documentation in a scrollable viewport with keyboard and mouse navigation.
Package tui provides a Bubble Tea TUI for browsing Stripe documentation in a scrollable viewport with keyboard and mouse navigation.
Package ui provides shared visual styles and components for the TUI.
Package ui provides shared visual styles and components for the TUI.

Jump to

Keyboard shortcuts

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