config

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package config handles loading configuration from .gonerc.yaml files.

Index

Constants

View Source
const (
	MaxConcurrency = 1024
	MaxTimeout     = 300 // seconds
	MaxRetries     = 10
)

Upper bounds for check settings. These exist to keep a single .gonerc.yaml typo (e.g. concurrency: 100000, timeout: 99999) from spawning a fork-bomb's worth of HTTP workers or hanging a CI job for a day. The limits are generous — well above any legitimate use — and are validated at load time so the failure is loud and immediate.

View Source
const DefaultConfigFileName = ".gonerc.yaml"

DefaultConfigFileName is the default configuration file name.

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckConfig added in v0.1.3

type CheckConfig struct {
	// Concurrency is the number of concurrent workers.
	// Default: 50 (set at runtime if 0)
	Concurrency int `yaml:"concurrency"`

	// Timeout is the request timeout in seconds.
	// Default: 5 (set at runtime if 0)
	Timeout int `yaml:"timeout"`

	// Retries is the number of retry attempts for failed requests.
	// Default: 1 (set at runtime if 0)
	Retries int `yaml:"retries"`

	// Strict fails on malformed files instead of skipping them.
	// Default: false
	Strict bool `yaml:"strict"`

	// AllowPrivateHosts permits checking URLs that resolve to loopback,
	// private, link-local and other reserved IP ranges.
	// Default: false (blocked to prevent SSRF when scanning untrusted
	// documents). Users who legitimately reference intranet hosts should
	// opt in via this setting or via the --allow-private-hosts flag.
	AllowPrivateHosts bool `yaml:"allow_private_hosts"`
}

CheckConfig holds checker settings for URL validation.

type Config

type Config struct {
	// Types specifies which file types to scan.
	// Supported: md, json, yaml, toml, xml
	// If empty, defaults to ["md"] at runtime.
	Types []string `yaml:"types"`

	// Scan holds scanner configuration.
	Scan ScanConfig `yaml:"scan"`

	// Check holds checker configuration.
	Check CheckConfig `yaml:"check"`

	// Output holds output preferences.
	Output OutputConfig `yaml:"output"`

	// Ignore holds URL ignore rules (backwards compatible).
	Ignore IgnoreConfig `yaml:"ignore"`
}

Config represents the complete configuration structure.

func FindAndLoad

func FindAndLoad(startDir, stopAt string) (*Config, error)

FindAndLoad searches for a config file starting from startDir and walking up the directory chain until it finds one or reaches stopAt (inclusive).

stopAt MUST be an ancestor of (or equal to) startDir; otherwise the search is restricted to startDir alone. This bound prevents an unrelated .gonerc.yaml in a parent directory — including world-writable paths like /tmp or a shared home directory — from silently altering behavior when the user runs `gone` from a subdirectory of an unfamiliar workspace.

Both paths are cleaned before comparison so callers don't need to normalize them. An empty stopAt is treated as startDir (no upward walk at all).

func Load

func Load() (*Config, error)

Load reads configuration from .gonerc.yaml in the current directory. Returns an empty config if the file doesn't exist (not an error). Returns an error only if the file exists but cannot be parsed.

func LoadFrom

func LoadFrom(path string) (*Config, error)

LoadFrom reads configuration from a specific path. Returns an empty config if the file doesn't exist (not an error). Returns an error only if the file exists but cannot be parsed.

func (*Config) GetShowDead added in v0.1.3

func (c *Config) GetShowDead() bool

GetShowDead returns the ShowDead value, defaulting to true if not set.

func (*Config) GetShowWarnings added in v0.1.3

func (c *Config) GetShowWarnings() bool

GetShowWarnings returns the ShowWarnings value, defaulting to true if not set.

func (*Config) HasCheckConfig added in v0.1.3

func (c *Config) HasCheckConfig() bool

HasCheckConfig returns true if any check configuration is set.

func (*Config) HasIgnoreRules added in v0.1.3

func (c *Config) HasIgnoreRules() bool

HasIgnoreRules returns true if any ignore rules are defined.

func (*Config) HasOutputConfig added in v0.1.3

func (c *Config) HasOutputConfig() bool

HasOutputConfig returns true if any output configuration is set.

func (*Config) HasScanConfig added in v0.1.3

func (c *Config) HasScanConfig() bool

HasScanConfig returns true if any scan configuration is set.

func (*Config) HasTypes added in v0.1.3

func (c *Config) HasTypes() bool

HasTypes returns true if file types are configured.

func (*Config) IsEmpty

func (c *Config) IsEmpty() bool

IsEmpty returns true if the config has no settings defined. This checks all configuration sections, not just ignore rules.

func (*Config) Merge

func (c *Config) Merge(other *Config)

Merge combines another config into this one (additive for slices). This is useful for merging CLI flags with file config.

func (*Config) Validate added in v0.1.3

func (c *Config) Validate() error

Validate checks the configuration for errors. Returns an error if any configuration value is invalid.

type IgnoreConfig

type IgnoreConfig struct {
	// Domains to ignore (automatically includes subdomains).
	// Example: "example.com" will also match "www.example.com", "api.example.com".
	Domains []string `yaml:"domains"`

	// Patterns are glob patterns for URL matching.
	// Example: "*.local/*", "*/internal/*"
	Patterns []string `yaml:"patterns"`

	// Regex are regular expression patterns for URL matching.
	// Example: ".*\\.test$", ".*/v[0-9]+/draft/.*"
	Regex []string `yaml:"regex"`
}

IgnoreConfig holds all ignore rules.

type OutputConfig added in v0.1.3

type OutputConfig struct {
	// Format specifies the default output format.
	// Valid: json, yaml, xml, junit, markdown
	// Empty means text output to stdout.
	Format string `yaml:"format"`

	// ShowAlive shows alive links in output.
	// Default: false
	ShowAlive bool `yaml:"showAlive"`

	// ShowWarnings shows warning links (redirects, blocked) in output.
	// Default: true (set at runtime)
	ShowWarnings *bool `yaml:"showWarnings"`

	// ShowDead shows dead links and errors in output.
	// Default: true (set at runtime)
	ShowDead *bool `yaml:"showDead"`

	// ShowStats shows performance statistics.
	// Default: false
	ShowStats bool `yaml:"showStats"`
}

OutputConfig holds output preferences for the check command.

type ScanConfig added in v0.1.3

type ScanConfig struct {
	// Include specifies glob patterns for paths to include.
	// If empty, all files matching the types are included.
	// Example: ["docs/**", "README.md"]
	Include []string `yaml:"include"`

	// Exclude specifies glob patterns for paths to exclude.
	// Example: ["node_modules/**", "vendor/**", "**/testdata/**"]
	Exclude []string `yaml:"exclude"`
}

ScanConfig holds scanner settings for file discovery.

Jump to

Keyboard shortcuts

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