Skip to main content

Overview

The config package manages all configuration settings for the Camera Workflow application. It uses Viper for flexible configuration from multiple sources: defaults, YAML files, environment variables, and command-line flags.

Types

Config

Main configuration structure containing all application settings.
type Config struct {
    // Directories
    SourceDir string
    DestDir   string

    // Processing
    MaxJobs        int
    DryRun         bool
    CopyOnly       bool
    VerifyChecksum bool
    JSONMode       bool

    // Image settings
    PhotoFormat      string
    PhotoQualityAVIF int
    PhotoQualityWebP int

    // Video settings
    VideoCodec        string
    VideoCRF          int
    VideoAcceleration bool

    // Organization
    OrganizeByDate bool
    KeepOriginals  bool
    Language       string

    // Security
    SkipDiskSpaceCheck     bool
    ConversionTimeoutPhoto time.Duration
    ConversionTimeoutVideo time.Duration
    MinOutputSizeRatio     float64
    MinOutputSizeRatioAVIF float64
    MinOutputSizeRatioWebP float64

    // Supported formats
    PhotoFormats []string
    VideoFormats []string

    // Adaptive worker management
    AdaptiveWorkers AdaptiveWorkerConfig
}

Configuration Fields

Directories

SourceDir
string
Source directory containing media files to convert
DestDir
string
Destination directory for converted files

Processing

MaxJobs
int
default:"CPU-2"
Maximum number of parallel conversion jobs
DryRun
bool
default:"false"
Preview mode - no files will be converted
CopyOnly
bool
default:"false"
Copy mode - files are copied without conversion
VerifyChecksum
bool
default:"false"
Enable checksum verification for copied files
JSONMode
bool
default:"false"
Enable JSON output for Tauri/programmatic integration

Image Settings

PhotoFormat
string
default:"avif"
Output format for photos (“avif” or “webp”)
PhotoQualityAVIF
int
default:"80"
Quality setting for AVIF conversion (1-100)
PhotoQualityWebP
int
default:"85"
Quality setting for WebP conversion (1-100)

Video Settings

VideoCodec
string
default:"h265"
Video codec (“h265”, “h264”, or “av1”)
VideoCRF
int
default:"28"
Constant Rate Factor for video encoding (0-51, lower = better quality)
VideoAcceleration
bool
default:"true"
Enable hardware acceleration when available

Organization

OrganizeByDate
bool
default:"true"
Organize files by date (YYYY/MM-Month/YYYY-MM-DD/)
KeepOriginals
bool
default:"true"
Preserve original files after conversion
Language
string
default:"en"
Language for month names (“en”, “fr”, “es”, “de”)

AdaptiveWorkerConfig

Configuration for adaptive worker pool management.
type AdaptiveWorkerConfig struct {
    Enabled       bool
    MinWorkers    int
    MaxWorkers    int
    CPUHigh       float64
    CPULow        float64
    MemLowPercent float64
    CheckInterval time.Duration
}
Enabled
bool
default:"false"
Enable adaptive worker management
MinWorkers
int
default:"1"
Minimum number of workers
MaxWorkers
int
default:"6"
Maximum number of workers
CPUHigh
float64
default:"80.0"
CPU threshold to scale down workers (%)
CPULow
float64
default:"50.0"
CPU threshold to scale up workers (%)
MemLowPercent
float64
default:"20.0"
Memory threshold to scale down workers (% available)
CheckInterval
time.Duration
default:"3s"
Interval for checking system resources

Functions

NewConfig

Creates a new Config instance with default values and loads settings from Viper.
func NewConfig() *Config
config
*Config
A new Config instance with defaults and loaded settings

Example

import "github.com/Azilone/Camera-Workflow/internal/config"

cfg := config.NewConfig()
cfg.SourceDir = "/path/to/source"
cfg.DestDir = "/path/to/destination"

Default Values

The following defaults are applied when values are not explicitly set:
max_jobs: CPU-2
photo_format: "avif"
photo_quality_avif: 80
photo_quality_webp: 85
video_codec: "h265"
video_crf: 28
video_acceleration: true
organize_by_date: true
keep_originals: true
timeout_photo: 300s
timeout_video: 1800s
min_output_size_ratio: 0.005

Methods

Validate

Validates configuration and derives dependent values.
func (c *Config) Validate() error
error
error
Returns an error if configuration is invalid

Validation Rules

  • Sets VerifyChecksum = true when CopyOnly = true
  • Ensures MaxJobs is between 1 and CPU count
  • Validates adaptive worker min/max constraints
  • Ensures size ratio thresholds are positive

Configuration Sources

Settings are loaded in order of priority (highest to lowest):
  1. Command-line flags (highest priority)
  2. Environment variables
  3. YAML config file ($HOME/.media-converter.yaml)
  4. Default values (lowest priority)

YAML Configuration Example

# ~/.media-converter.yaml
max_jobs: 4
photo_format: "avif"
photo_quality_avif: 85
video_codec: "h265"
video_crf: 25
keep_originals: true
organize_by_date: true
language: "en"

adaptive_workers:
  enabled: true
  min: 1
  max: 4
  cpu_high: 85.0
  cpu_low: 50.0
  mem_low_percent: 15.0
  interval_seconds: 5

Supported Formats

Photo Formats

PhotoFormats: []string{
    "jpg", "jpeg", "heic", "heif", "cr2", "arw", "nef", "dng",
    "tiff", "tif", "png", "raw", "bmp", "gif", "webp",
}

Video Formats

VideoFormats: []string{
    "mov", "mp4", "avi", "mkv", "m4v", "mts", "m2ts", "mpg",
    "mpeg", "wmv", "flv", "3gp", "3gpp",
}
  • Converter - Uses Config for conversion settings
  • Security - Uses Config for validation thresholds

Build docs developers (and LLMs) love