config

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package config loads defSource runtime configuration from environment variables.

Precedence (highest to lowest):

  1. Explicit CLI flag value (callers pass flag defaults as cfg.Field)
  2. Environment variable (read by Load)
  3. Built-in default (hard-coded in Load)

Usage pattern for cmd mains:

cfg := config.Load()
dbPath := flag.String("db", cfg.DBPath, "Path to SQLite database")
flag.Parse()

After flag.Parse, *dbPath holds the explicit flag value when the user passed --db, or the env-var-aware default from cfg.DBPath otherwise.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DBPath is the filesystem path to the SQLite database file.
	// Env: DEFSOURCE_DB_PATH. Default: "./data/defsource.db".
	DBPath string

	// MaxRetries is the maximum number of retry attempts for a failing HTTP fetch.
	// Env: DEFSOURCE_MAX_RETRIES. Default: 3.
	MaxRetries int

	// TokenBudget is the approximate token limit for formatted doc snippet output.
	// Env: DEFSOURCE_TOKEN_BUDGET. Default: 8000.
	TokenBudget int

	// UserAgent is the HTTP User-Agent header sent by the crawler fetcher.
	// Env: DEFSOURCE_USER_AGENT. Default: "defSource/1.0 (open-source documentation indexer)".
	UserAgent string

	// ServerAddr is the TCP address the HTTP API server listens on.
	// Env: DEFSOURCE_ADDR. Default: ":8080".
	ServerAddr string

	// Workers is the number of concurrent crawler worker goroutines.
	// Env: DEFSOURCE_WORKERS. Default: 10.
	Workers int

	// RequestsPerSecond is the crawler fetch rate limit in requests per second.
	// Env: DEFSOURCE_RPS. Default: 10.
	RequestsPerSecond int

	// CORSOrigin is the value of the Access-Control-Allow-Origin header.
	// Env: DEFSOURCE_CORS_ORIGIN. Default: "*".
	CORSOrigin string

	// CacheDir is the directory where downloaded WordPress source tarballs are
	// extracted and cached (one subdirectory per version).
	// Env: DEFSOURCE_CACHE_DIR. Default: <os.UserCacheDir>/defsource/wpgithub,
	// falling back to "./data/cache/wpgithub" when the user cache dir is unavailable.
	CacheDir string

	// WPVersion is the WordPress release to download. Empty means resolve the
	// latest release tag from the GitHub tags API.
	// Env: DEFSOURCE_WP_VERSION. Default: "" (latest).
	WPVersion string

	// GitHubToken is an optional GitHub API token used to raise the API rate
	// limit when resolving the latest version. It is never sent to the tarball
	// (codeload) download.
	// Env: GITHUB_TOKEN, then GH_TOKEN. Default: "".
	GitHubToken string
}

Config holds all runtime configuration for defSource binaries. Fields are populated by Load from environment variables with built-in defaults; CLI flags should take their default values from this struct so that env-var overrides are honoured when no flag is passed explicitly.

func Load

func Load() Config

Load returns a Config populated from environment variables, falling back to built-in defaults for any variable that is absent or empty. The returned Config should be used as the source of default values for CLI flag definitions so that the env-var layer is respected when no explicit flag is passed by the operator.

Jump to

Keyboard shortcuts

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