config

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package config loads and validates scry configuration from environment variables.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidOutputFormats

func ValidOutputFormats() []string

ValidOutputFormats returns the accepted output format names in sorted order.

Types

type Config

type Config struct {
	// Crawler settings.
	MaxDepth       int           `env:"SCRY_MAX_DEPTH"       envDefault:"5"`
	MaxPages       int           `env:"SCRY_MAX_PAGES"       envDefault:"500"`
	Concurrency    int           `env:"SCRY_CONCURRENCY"     envDefault:"10"`
	RequestTimeout time.Duration `env:"SCRY_REQUEST_TIMEOUT" envDefault:"10s"`
	RateLimit      int           `env:"SCRY_RATE_LIMIT"      envDefault:"50"`
	UserAgent      string        `env:"SCRY_USER_AGENT"      envDefault:"scry/1.0"`
	RespectRobots  bool          `env:"SCRY_RESPECT_ROBOTS"  envDefault:"true"`

	// Output settings.
	OutputFormat string `env:"SCRY_OUTPUT"      envDefault:"terminal"`
	OutputFile   string `env:"SCRY_OUTPUT_FILE" envDefault:""`
	FailOn       string `env:"SCRY_FAIL_ON"     envDefault:""`

	// Browser mode.
	BrowserMode    bool   `env:"SCRY_BROWSER_MODE"    envDefault:"false"`
	BrowserlessURL string `env:"SCRY_BROWSERLESS_URL" envDefault:"http://localhost:3000"`

	// Lighthouse.
	LighthouseEnabled bool   `env:"SCRY_LIGHTHOUSE"      envDefault:"false"`
	LighthouseMode    string `env:"SCRY_LIGHTHOUSE_MODE"  envDefault:"psi"`
	PSIAPIKey         string `env:"SCRY_PSI_API_KEY"      envDefault:""`
	PSIStrategy       string `env:"SCRY_PSI_STRATEGY"     envDefault:"mobile"`

	// Logging.
	LogLevel  string `env:"SCRY_LOG_LEVEL"  envDefault:"info"`
	LogFormat string `env:"SCRY_LOG_FORMAT" envDefault:"pretty"`

	// Filtering.
	FilterSeverity string `env:"SCRY_FILTER_SEVERITY" envDefault:""`
	FilterCategory string `env:"SCRY_FILTER_CATEGORY" envDefault:""`

	// Parallel domains.
	ParallelDomains int `env:"SCRY_PARALLEL_DOMAINS" envDefault:"3"`

	// Metrics.
	MetricsPushURL string `env:"SCRY_METRICS_PUSH_URL" envDefault:""`

	// Checkpoint / Incremental.
	CheckpointFile  string `env:"SCRY_CHECKPOINT_FILE"  envDefault:""`
	ResumeFile      string `env:"SCRY_RESUME_FILE"      envDefault:""`
	IncrementalFile string `env:"SCRY_INCREMENTAL_FILE" envDefault:""`

	// Custom rules.
	RulesFile string `env:"SCRY_RULES_FILE" envDefault:""`

	// Baseline comparison.
	SaveBaselineFile    string `env:"SCRY_SAVE_BASELINE"    envDefault:""`
	CompareBaselineFile string `env:"SCRY_COMPARE_BASELINE" envDefault:""`

	// CLI-only fields (not from env).
	IncludePatterns []string `env:"-"`
	ExcludePatterns []string `env:"-"`
}

Config holds all configuration for scry.

func Load

func Load() (*Config, error)

Load parses environment variables into a Config and validates it.

func LoadWithFile

func LoadWithFile(configPath string) (*Config, error)

LoadWithFile performs the full configuration load sequence:

  1. Load environment variables and defaults via Load().
  2. Discover the YAML config file.
  3. If found, parse and merge YAML values (only non-nil fields).
  4. Re-validate the merged configuration.

func (*Config) OutputFormats

func (c *Config) OutputFormats() []string

OutputFormats splits OutputFormat by comma and trims whitespace from each element.

type YAMLConfig

type YAMLConfig struct {
	Crawl struct {
		MaxDepth      *int     `yaml:"max_depth"`
		MaxPages      *int     `yaml:"max_pages"`
		Concurrency   *int     `yaml:"concurrency"`
		RespectRobots *bool    `yaml:"respect_robots"`
		Exclude       []string `yaml:"exclude"`
		Include       []string `yaml:"include"`
		RateLimit     *int     `yaml:"rate_limit"`
		Timeout       *string  `yaml:"timeout"`
		UserAgent     *string  `yaml:"user_agent"`
	} `yaml:"crawl"`

	Output struct {
		Formats []string `yaml:"formats"`
		File    *string  `yaml:"file"`
		FailOn  *string  `yaml:"fail_on"`
	} `yaml:"output"`

	Filter struct {
		Severity *string `yaml:"severity"`
		Category *string `yaml:"category"`
	} `yaml:"filter"`

	Lighthouse struct {
		Enabled  *bool   `yaml:"enabled"`
		Mode     *string `yaml:"mode"`
		Strategy *string `yaml:"strategy"`
	} `yaml:"lighthouse"`

	Browser struct {
		Enabled        *bool   `yaml:"enabled"`
		BrowserlessURL *string `yaml:"browserless_url"`
	} `yaml:"browser"`

	Rules struct {
		File *string `yaml:"file"`
	} `yaml:"rules"`

	Baseline struct {
		Save    *string `yaml:"save"`
		Compare *string `yaml:"compare"`
	} `yaml:"baseline"`
}

YAMLConfig represents the configuration file structure. Pointer fields distinguish unset from zero values.

Jump to

Keyboard shortcuts

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