config

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package config provides configuration management for the gdl download tool. It handles retry policies, error handling preferences, output formats, and timeout values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultConfigPath

func DefaultConfigPath() (string, error)

DefaultConfigPath returns the default configuration file path.

Types

type Config

type Config struct {
	// Version is the configuration schema version
	Version string `json:"version" yaml:"version"`

	// RetryPolicy defines retry behavior
	RetryPolicy RetryPolicyConfig `json:"retry_policy" yaml:"retry_policy"`

	// ErrorHandling defines error handling preferences
	ErrorHandling ErrorHandlingConfig `json:"error_handling" yaml:"error_handling"`

	// OutputFormat defines output formatting
	OutputFormat OutputFormatConfig `json:"output_format" yaml:"output_format"`

	// Timeouts defines various timeout values
	Timeouts TimeoutConfig `json:"timeouts" yaml:"timeouts"`

	// Network defines network-related settings
	Network NetworkConfig `json:"network" yaml:"network"`

	// Storage defines storage-related settings
	Storage StorageConfig `json:"storage" yaml:"storage"`

	// Plugins defines plugin configurations
	Plugins []PluginConfig `json:"plugins,omitempty" yaml:"plugins,omitempty"`

	// Middleware defines middleware chain configuration
	Middleware []MiddlewareConfig `json:"middleware,omitempty" yaml:"middleware,omitempty"`

	// Hooks defines event hook configurations
	Hooks map[string][]string `json:"hooks,omitempty" yaml:"hooks,omitempty"`
}

Config represents the complete configuration for the gdl application.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a configuration with sensible default values.

func (*Config) Clone

func (c *Config) Clone() *Config

Clone creates a deep copy of the configuration.

func (*Config) Merge

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

func (*Config) Validate

func (c *Config) Validate() error

type ConfigLoader

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

ConfigLoader handles loading and saving configuration.

func NewConfigLoader

func NewConfigLoader(configPath string) *ConfigLoader

NewConfigLoader creates a new configuration loader.

func (*ConfigLoader) Load

func (cl *ConfigLoader) Load() (*Config, error)

Load loads configuration from file, falling back to defaults if file doesn't exist.

func (*ConfigLoader) Save

func (cl *ConfigLoader) Save(config *Config) error

Save saves configuration to file.

type ConfigManager

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

ConfigManager provides high-level configuration management operations.

func NewConfigManager

func NewConfigManager(configPath string) (*ConfigManager, error)

NewConfigManager creates a new configuration manager.

func NewDefaultConfigManager

func NewDefaultConfigManager() (*ConfigManager, error)

NewDefaultConfigManager creates a configuration manager with default path.

func (*ConfigManager) GetConfig

func (cm *ConfigManager) GetConfig() *Config

GetConfig returns the current configuration.

func (*ConfigManager) ReloadConfig

func (cm *ConfigManager) ReloadConfig() error

ReloadConfig reloads the configuration from file.

func (*ConfigManager) SaveConfig

func (cm *ConfigManager) SaveConfig() error

SaveConfig saves the current configuration to file.

func (*ConfigManager) UpdateConfig

func (cm *ConfigManager) UpdateConfig(config *Config) error

UpdateConfig updates the configuration and saves it to file.

type ErrorHandlingConfig

type ErrorHandlingConfig struct {
	// VerboseErrors enables detailed error messages
	VerboseErrors bool `json:"verbose_errors" yaml:"verbose_errors"`

	// ShowStackTrace includes stack traces in error output
	ShowStackTrace bool `json:"show_stack_trace" yaml:"show_stack_trace"`

	// LogErrors enables error logging to file
	LogErrors bool `json:"log_errors" yaml:"log_errors"`

	// LogFile is the path to the error log file
	LogFile string `json:"log_file,omitempty" yaml:"log_file,omitempty"`

	// FailFast stops on first error instead of retrying
	FailFast bool `json:"fail_fast" yaml:"fail_fast"`

	// ErrorFormat defines how errors should be formatted (json, text, structured)
	ErrorFormat string `json:"error_format" yaml:"error_format"`

	// RecoveryEnabled enables intelligent error recovery suggestions
	RecoveryEnabled bool `json:"recovery_enabled" yaml:"recovery_enabled"`

	// NetworkDiagnostics enables network connectivity diagnostics
	NetworkDiagnostics bool `json:"network_diagnostics" yaml:"network_diagnostics"`
}

ErrorHandlingConfig defines error handling preferences.

type MiddlewareConfig

type MiddlewareConfig struct {
	Name     string                 `json:"name" yaml:"name"`
	Enabled  bool                   `json:"enabled" yaml:"enabled"`
	Priority int                    `json:"priority,omitempty" yaml:"priority,omitempty"`
	Settings map[string]interface{} `json:"settings,omitempty" yaml:"settings,omitempty"`
}

MiddlewareConfig represents the configuration for middleware

type NetworkConfig

type NetworkConfig struct {
	// UserAgent is the HTTP User-Agent string
	UserAgent string `json:"user_agent,omitempty" yaml:"user_agent,omitempty"`

	// MaxConcurrentDownloads limits the number of simultaneous downloads
	MaxConcurrentDownloads int `json:"max_concurrent_downloads" yaml:"max_concurrent_downloads"`

	// ChunkSize is the size of download chunks in bytes
	ChunkSize int `json:"chunk_size" yaml:"chunk_size"`

	// BufferSize is the I/O buffer size in bytes
	BufferSize int `json:"buffer_size" yaml:"buffer_size"`

	// FollowRedirects enables automatic redirect following
	FollowRedirects bool `json:"follow_redirects" yaml:"follow_redirects"`

	// MaxRedirects is the maximum number of redirects to follow
	MaxRedirects int `json:"max_redirects" yaml:"max_redirects"`

	// InsecureTLS disables TLS certificate verification
	InsecureTLS bool `json:"insecure_tls" yaml:"insecure_tls"`
}

NetworkConfig defines network-related configuration.

type OutputFormatConfig

type OutputFormatConfig struct {
	// Format defines the output format (json, yaml, text, table)
	Format string `json:"format" yaml:"format"`

	// Pretty enables pretty-printing for structured formats
	Pretty bool `json:"pretty" yaml:"pretty"`

	// Color enables colored output
	Color bool `json:"color" yaml:"color"`

	// ShowProgress enables progress bars and indicators
	ShowProgress bool `json:"show_progress" yaml:"show_progress"`

	// Quiet reduces output verbosity
	Quiet bool `json:"quiet" yaml:"quiet"`

	// Verbose increases output verbosity
	Verbose bool `json:"verbose" yaml:"verbose"`

	// TimestampFormat defines timestamp format for logs
	TimestampFormat string `json:"timestamp_format,omitempty" yaml:"timestamp_format,omitempty"`

	// LogLevel defines the minimum log level to output
	LogLevel string `json:"log_level" yaml:"log_level"`
}

OutputFormatConfig defines output format settings.

type PluginConfig

type PluginConfig struct {
	Enabled  bool                   `json:"enabled" yaml:"enabled"`
	Name     string                 `json:"name" yaml:"name"`
	Type     string                 `json:"type" yaml:"type"`
	Path     string                 `json:"path,omitempty" yaml:"path,omitempty"`
	Settings map[string]interface{} `json:"settings,omitempty" yaml:"settings,omitempty"`
	Priority int                    `json:"priority,omitempty" yaml:"priority,omitempty"`
}

PluginConfig represents the configuration for a single plugin

type RetryPolicyConfig

type RetryPolicyConfig struct {
	// MaxRetries is the maximum number of retry attempts
	MaxRetries int `json:"max_retries" yaml:"max_retries"`

	// BaseDelay is the initial delay between retries
	BaseDelay time.Duration `json:"base_delay" yaml:"base_delay"`

	// MaxDelay is the maximum delay between retries
	MaxDelay time.Duration `json:"max_delay" yaml:"max_delay"`

	// BackoffFactor is the exponential backoff multiplier
	BackoffFactor float64 `json:"backoff_factor" yaml:"backoff_factor"`

	// Jitter enables random jitter in retry delays
	Jitter bool `json:"jitter" yaml:"jitter"`

	// Strategy defines the retry strategy type (exponential, linear, constant, custom)
	Strategy string `json:"strategy" yaml:"strategy"`

	// RetryableErrors is a list of error types that should be retried
	RetryableErrors []string `json:"retryable_errors,omitempty" yaml:"retryable_errors,omitempty"`

	// NonRetryableErrors is a list of error types that should never be retried
	NonRetryableErrors []string `json:"non_retryable_errors,omitempty" yaml:"non_retryable_errors,omitempty"`
}

RetryPolicyConfig defines the retry policy configuration.

type StorageConfig

type StorageConfig struct {
	// DefaultDownloadDir is the default directory for downloads
	DefaultDownloadDir string `json:"default_download_dir,omitempty" yaml:"default_download_dir,omitempty"`

	// CreateDirs enables automatic directory creation
	CreateDirs bool `json:"create_dirs" yaml:"create_dirs"`

	// OverwriteExisting allows overwriting existing files
	OverwriteExisting bool `json:"overwrite_existing" yaml:"overwrite_existing"`

	// ResumeSupport enables resume support for interrupted downloads
	ResumeSupport bool `json:"resume_support" yaml:"resume_support"`

	// MinFreeSpace is the minimum free space required before downloading
	MinFreeSpace int64 `json:"min_free_space" yaml:"min_free_space"`

	// TempDir is the directory for temporary files
	TempDir string `json:"temp_dir,omitempty" yaml:"temp_dir,omitempty"`
}

StorageConfig defines storage-related configuration.

type TimeoutConfig

type TimeoutConfig struct {
	// ConnectTimeout is the timeout for establishing connections
	ConnectTimeout time.Duration `json:"connect_timeout" yaml:"connect_timeout"`

	// ReadTimeout is the timeout for reading data
	ReadTimeout time.Duration `json:"read_timeout" yaml:"read_timeout"`

	// WriteTimeout is the timeout for writing data
	WriteTimeout time.Duration `json:"write_timeout" yaml:"write_timeout"`

	// RequestTimeout is the overall timeout for HTTP requests
	RequestTimeout time.Duration `json:"request_timeout" yaml:"request_timeout"`

	// DownloadTimeout is the maximum time allowed for a complete download
	DownloadTimeout time.Duration `json:"download_timeout" yaml:"download_timeout"`

	// IdleTimeout is the timeout for idle connections
	IdleTimeout time.Duration `json:"idle_timeout" yaml:"idle_timeout"`
}

TimeoutConfig defines timeout values for various operations.

Jump to

Keyboard shortcuts

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