Documentation
¶
Overview ¶
Package config provides application configuration management.
Index ¶
- Constants
- Variables
- func GenerateAPIKey() (string, error)
- type AudioConfig
- type ChannelImbalanceDetectionConfig
- type Config
- func (c *Config) AddRecorder(recorder *types.Recorder) error
- func (c *Config) AddStream(stream *types.Stream) error
- func (c *Config) ApplySettings(s *SettingsUpdate) error
- func (c *Config) AudioInput() string
- func (c *Config) ConfiguredStreams() []types.Stream
- func (c *Config) FFmpegPath() string
- func (c *Config) GraphConfig() types.GraphConfig
- func (c *Config) Load() error
- func (c *Config) Recorder(id string) *types.Recorder
- func (c *Config) RecordingAPIKey() string
- func (c *Config) RemoveRecorder(id string) error
- func (c *Config) RemoveStream(id string) error
- func (c *Config) SetRecordingAPIKey(key string) error
- func (c *Config) Snapshot() Snapshot
- func (c *Config) Stream(id string) *types.Stream
- func (c *Config) UpdateRecorder(recorder *types.Recorder) error
- func (c *Config) UpdateStream(stream *types.Stream) error
- type ConfigData
- type EmailConfig
- type NotificationsConfig
- type RecordingConfig
- type SettingsUpdate
- type SilenceDetectionConfig
- type Snapshot
- type StreamingConfig
- type SystemConfig
- type WebConfig
- type WebhookConfig
Constants ¶
const ( // DefaultWebPort is the default HTTP server port (8080). DefaultWebPort = 8080 // DefaultZabbixPort is the default Zabbix trapper port. DefaultZabbixPort = 10051 // DefaultWebUsername is the default web interface username (admin). DefaultWebUsername = "admin" // DefaultWebPassword is the default web interface password (encoder). DefaultWebPassword = "encoder" // DefaultSilenceThreshold is the default silence detection threshold (-40 dB). DefaultSilenceThreshold = -40.0 // DefaultSilenceDurationMs is the default silence duration before alert (15 seconds). DefaultSilenceDurationMs = 15000 // DefaultSilenceRecoveryMs is the default recovery duration before clearing alert (5 seconds). DefaultSilenceRecoveryMs = 5000 // DefaultPeakHoldMs is the default VU meter peak hold duration (3 seconds). DefaultPeakHoldMs = 3000 // DefaultChannelImbalanceThreshold is the default L/R imbalance threshold in dB. DefaultChannelImbalanceThreshold = 12.0 // DefaultChannelImbalanceDurationMs is the default imbalance duration before alert (15 seconds). DefaultChannelImbalanceDurationMs = 15000 // DefaultChannelImbalanceRecoveryMs is the default balance duration before recovery (5 seconds). DefaultChannelImbalanceRecoveryMs = 5000 // DefaultStationName is the default station display name shown in the web UI. DefaultStationName = "ZuidWest FM" // DefaultStationColorLight is the default accent color for light theme (#E6007E). DefaultStationColorLight = "#E6007E" // DefaultStationColorDark is the default accent color for dark theme (#E6007E). DefaultStationColorDark = "#E6007E" // DefaultRecordingMaxDurationMinutes is the default max duration for on-demand recordings (4 hours). DefaultRecordingMaxDurationMinutes = 240 )
Variables ¶
var ( // ErrStreamNotFound is returned when a stream ID does not exist in config. ErrStreamNotFound = errors.New("stream not found") // ErrInvalidStreamConfig is returned when a stream change would make config invalid. ErrInvalidStreamConfig = errors.New("invalid stream config") // ErrRecorderNotFound is returned when a recorder ID does not exist in config. ErrRecorderNotFound = errors.New("recorder not found") )
Sentinel errors for configuration operations.
Functions ¶
func GenerateAPIKey ¶ added in v0.5.0
GenerateAPIKey returns a new random API key.
Types ¶
type AudioConfig ¶ added in v0.2.0
type AudioConfig struct {
// Input is the audio input device identifier (platform-specific).
Input string `json:"input"`
}
AudioConfig holds audio input configuration.
type ChannelImbalanceDetectionConfig ¶ added in v0.30.0
type ChannelImbalanceDetectionConfig struct {
// ThresholdDB is the strict L/R difference threshold in dB.
ThresholdDB float64 `json:"threshold_db"`
// DurationMs is how long the imbalance must persist before alerting.
DurationMs int64 `json:"duration_ms"`
// RecoveryMs is how long balance must hold before clearing the alert.
RecoveryMs int64 `json:"recovery_ms"`
}
ChannelImbalanceDetectionConfig holds L/R imbalance detector settings.
type Config ¶
type Config struct {
// Keep JSON-backed fields in ConfigData so Load can copy persisted state in
// one assignment without copying the mutex.
ConfigData
// contains filtered or unexported fields
}
Config holds all application configuration and is safe for concurrent use.
func (*Config) AddRecorder ¶ added in v0.5.0
AddRecorder adds a recorder to the configuration and persists the change.
func (*Config) AddStream ¶ added in v0.6.1
AddStream adds a stream to the configuration and persists the change.
func (*Config) ApplySettings ¶ added in v0.6.1
func (c *Config) ApplySettings(s *SettingsUpdate) error
ApplySettings validates and updates all settings atomically with a single file write.
func (*Config) AudioInput ¶
AudioInput returns the configured audio input device.
func (*Config) ConfiguredStreams ¶ added in v0.6.1
ConfiguredStreams returns a copy of all streams.
func (*Config) FFmpegPath ¶ added in v0.4.0
FFmpegPath returns the configured FFmpeg binary path.
func (*Config) GraphConfig ¶ added in v0.5.0
func (c *Config) GraphConfig() types.GraphConfig
GraphConfig returns a copy of the current Graph/Email configuration.
func (*Config) Load ¶
Load reads and validates an existing config file. If the file does not exist, Load writes a minimal validated default config. Existing files are decoded as-is; omitted optional Web, SilenceDetection, and ChannelImbalanceDetection fields inherit defaults. Explicit nulls remain zero so validation rejects malformed input, preserving strict null semantics while older minimal configs stay valid. Required system settings must still be present and valid.
func (*Config) Recorder ¶ added in v0.5.0
Recorder returns a copy of the recorder with the given ID, or nil if not found.
func (*Config) RecordingAPIKey ¶ added in v0.5.0
RecordingAPIKey returns the API key for recording REST endpoints.
func (*Config) RemoveRecorder ¶ added in v0.5.0
RemoveRecorder removes a recorder from the configuration and persists the change.
func (*Config) RemoveStream ¶ added in v0.6.1
RemoveStream removes a stream from the configuration and persists the change.
func (*Config) SetRecordingAPIKey ¶ added in v0.5.0
SetRecordingAPIKey updates the recording API key and persists the change.
func (*Config) Snapshot ¶ added in v0.2.3
Snapshot returns a point-in-time copy of all configuration values.
func (*Config) Stream ¶ added in v0.6.1
Stream returns a copy of the stream with the given ID, or nil if not found.
func (*Config) UpdateRecorder ¶ added in v0.5.0
UpdateRecorder updates a recorder in the configuration and persists the change.
type ConfigData ¶ added in v0.10.0
type ConfigData struct {
// System contains system-level configuration.
System SystemConfig `json:"system"`
// Web contains web UI branding settings.
Web WebConfig `json:"web"`
// Audio contains audio input settings.
Audio AudioConfig `json:"audio"`
// SilenceDetection contains silence detection settings.
SilenceDetection SilenceDetectionConfig `json:"silence_detection"`
// ChannelImbalanceDetection contains L/R imbalance detector settings.
ChannelImbalanceDetection ChannelImbalanceDetectionConfig `json:"channel_imbalance_detection"`
// SilenceDump contains silence dump settings.
SilenceDump types.SilenceDumpConfig `json:"silence_dump"`
// Notifications contains notification settings.
Notifications NotificationsConfig `json:"notifications"`
// Streaming contains stream settings.
Streaming StreamingConfig `json:"streaming"`
// Recording contains recording settings.
Recording RecordingConfig `json:"recording"`
}
ConfigData holds the JSON-backed application configuration fields.
type EmailConfig ¶ added in v0.2.0
type EmailConfig struct {
// TenantID is the Azure AD tenant ID for Graph API authentication.
TenantID string `json:"tenant_id"`
// ClientID is the Azure app registration client ID.
ClientID string `json:"client_id"`
// ClientSecret is the Azure app registration client secret.
ClientSecret string `json:"client_secret"` //nolint:gosec // G117: intentional config field for Azure auth
// FromAddress is the shared mailbox address to send emails from.
FromAddress string `json:"from_address"`
// Recipients is a comma-separated list of email addresses to notify.
Recipients string `json:"recipients"`
// Events controls which silence events trigger email notifications.
Events types.EventSubscriptions `json:"events"`
}
EmailConfig holds Microsoft Graph email settings.
type NotificationsConfig ¶ added in v0.2.0
type NotificationsConfig struct {
// Webhook contains webhook notification settings.
Webhook WebhookConfig `json:"webhook"`
// Email contains Microsoft Graph email settings.
Email EmailConfig `json:"email"`
// Zabbix contains Zabbix notification settings.
Zabbix types.ZabbixConfig `json:"zabbix"`
}
NotificationsConfig holds notification settings.
type RecordingConfig ¶ added in v0.6.0
type RecordingConfig struct {
// APIKey is the secret key for external recording control via REST API.
APIKey string `json:"api_key"` //nolint:gosec // G117: intentional config field for recording API auth
// MaxDurationMinutes is the maximum allowed duration for on-demand recordings.
MaxDurationMinutes int `json:"max_duration_minutes"`
// Recorders lists configured recording destinations.
Recorders []types.Recorder `json:"recorders"`
}
RecordingConfig holds recording configuration.
type SettingsUpdate ¶ added in v0.6.1
type SettingsUpdate struct {
// AudioInput is the audio input device identifier (platform-specific).
AudioInput string `json:"audio_input"`
// SilenceThreshold is the audio level in dB below which silence is detected.
SilenceThreshold float64 `json:"silence_threshold"`
// SilenceDurationMs is how long audio must be below threshold before alerting.
SilenceDurationMs int64 `json:"silence_duration_ms"`
// SilenceRecoveryMs is how long audio must be above threshold before clearing the alert.
SilenceRecoveryMs int64 `json:"silence_recovery_ms"`
// PeakHoldMs is how long the VU meter holds peak values before decay.
PeakHoldMs int64 `json:"peak_hold_ms"`
// ChannelImbalanceThreshold is the strict L/R difference threshold in dB.
ChannelImbalanceThreshold float64 `json:"channel_imbalance_threshold"`
// ChannelImbalanceDurationMs is how long the imbalance must persist before alerting.
ChannelImbalanceDurationMs int64 `json:"channel_imbalance_duration_ms"`
// ChannelImbalanceRecoveryMs is how long balance must hold before clearing the alert.
ChannelImbalanceRecoveryMs int64 `json:"channel_imbalance_recovery_ms"`
// SilenceDumpEnabled reports whether silence audio dumping is enabled.
SilenceDumpEnabled bool `json:"silence_dump_enabled"`
// SilenceDumpRetentionDays is how many days to keep silence dump files.
SilenceDumpRetentionDays int `json:"silence_dump_retention_days"`
// WebhookURL is the endpoint to POST silence alerts to.
WebhookURL string `json:"webhook_url"`
// WebhookEvents controls which silence events trigger webhook notifications.
WebhookEvents types.EventSubscriptions `json:"webhook_events"`
// EmailEvents controls which silence events trigger email notifications.
EmailEvents types.EventSubscriptions `json:"email_events"`
// ZabbixEvents controls which silence events trigger Zabbix notifications.
// This stays on the public Zabbix-specific shape to avoid exposing audio_dump.
ZabbixEvents types.ZabbixEventSubscriptions `json:"zabbix_events"`
// ZabbixServer is the Zabbix trapper server hostname or IP.
ZabbixServer string `json:"zabbix_server"`
// ZabbixPort is the Zabbix trapper server port.
ZabbixPort int `json:"zabbix_port"`
// ZabbixHost is the host name as registered in Zabbix.
ZabbixHost string `json:"zabbix_host"`
// ZabbixSilenceKey is the item key for Zabbix silence trapper values.
ZabbixSilenceKey string `json:"zabbix_silence_key"`
// ZabbixUploadKey is the item key for Zabbix upload trapper values.
ZabbixUploadKey string `json:"zabbix_upload_key"`
// GraphTenantID is the Azure AD tenant ID for Graph API authentication.
GraphTenantID string `json:"graph_tenant_id"`
// GraphClientID is the Azure app registration client ID.
GraphClientID string `json:"graph_client_id"`
// GraphClientSecret is the Azure app registration client secret.
GraphClientSecret string `json:"graph_client_secret"`
// GraphFromAddress is the shared mailbox address to send emails from.
GraphFromAddress string `json:"graph_from_address"`
// GraphRecipients is a comma-separated list of email addresses to notify.
GraphRecipients string `json:"graph_recipients"`
// RecordingMaxDurationMinutes is the maximum allowed duration for on-demand recordings.
RecordingMaxDurationMinutes int `json:"recording_max_duration_minutes"`
// ClearWebhookURL requests removal of the saved webhook URL.
// Must not be combined with a non-empty WebhookURL value (conflict -> 400).
ClearWebhookURL bool `json:"clear_webhook_url,omitempty"`
// ClearGraphClientSecret requests removal of the saved Graph client secret.
// Must not be combined with a non-empty GraphClientSecret value (conflict -> 400).
ClearGraphClientSecret bool `json:"clear_graph_client_secret,omitempty"`
}
SettingsUpdate contains all settings for atomic update.
func (*SettingsUpdate) Validate ¶ added in v0.6.2
func (s *SettingsUpdate) Validate() []string
Validate checks all settings fields and returns all validation errors.
type SilenceDetectionConfig ¶ added in v0.2.0
type SilenceDetectionConfig struct {
// ThresholdDB is the audio level in dB below which silence is detected.
ThresholdDB float64 `json:"threshold_db"`
// DurationMs is how long audio must be below threshold before alerting.
DurationMs int64 `json:"duration_ms"`
// RecoveryMs is how long audio must be above threshold before clearing the alert.
RecoveryMs int64 `json:"recovery_ms"`
// PeakHoldMs is how long the VU meter holds peak values before decay.
PeakHoldMs int64 `json:"peak_hold_ms"`
}
SilenceDetectionConfig holds silence detection settings.
type Snapshot ¶ added in v0.2.3
type Snapshot struct {
// WebPort is the HTTP server port to listen on.
WebPort int
// WebUser is the web interface login username.
WebUser string
// WebPassword is the web interface login password.
WebPassword string
// StationName is the station display name shown in the web UI header.
StationName string
// StationColorLight is the accent color for light theme (#RRGGBB).
StationColorLight string
// StationColorDark is the accent color for dark theme (#RRGGBB).
StationColorDark string
// AudioInput is the audio input device identifier (platform-specific).
AudioInput string
// SilenceThreshold is the audio level in dB below which silence is detected.
SilenceThreshold float64
// SilenceDurationMs is how long audio must be below threshold before alerting.
SilenceDurationMs int64
// SilenceRecoveryMs is how long audio must be above threshold before clearing the alert.
SilenceRecoveryMs int64
// PeakHoldMs is how long the VU meter holds peak values before decay.
PeakHoldMs int64
// ChannelImbalanceThreshold is the strict L/R difference threshold in dB.
ChannelImbalanceThreshold float64
// ChannelImbalanceDurationMs is how long the imbalance must persist before alerting.
ChannelImbalanceDurationMs int64
// ChannelImbalanceRecoveryMs is how long balance must hold before clearing the alert.
ChannelImbalanceRecoveryMs int64
// SilenceDumpEnabled reports whether silence audio dumping is enabled.
SilenceDumpEnabled bool
// SilenceDumpRetentionDays is how many days to keep silence dump files.
SilenceDumpRetentionDays int
// WebhookURL is the endpoint to POST silence alerts to.
WebhookURL string
// WebhookEvents controls which silence events trigger webhook notifications.
WebhookEvents types.EventSubscriptions
// EmailEvents controls which silence events trigger email notifications.
EmailEvents types.EventSubscriptions
// ZabbixEvents controls which silence events trigger Zabbix notifications.
// Internally this uses the unified event shape; AudioDump remains false for Zabbix.
ZabbixEvents types.EventSubscriptions
// ZabbixServer is the Zabbix trapper server hostname or IP.
ZabbixServer string
// ZabbixPort is the Zabbix trapper server port.
ZabbixPort int
// ZabbixHost is the host name as registered in Zabbix.
ZabbixHost string
// ZabbixSilenceKey is the item key for Zabbix silence trapper values.
ZabbixSilenceKey string
// ZabbixUploadKey is the item key for Zabbix upload trapper values.
ZabbixUploadKey string
// GraphTenantID is the Azure AD tenant ID for Graph API authentication.
GraphTenantID string
// GraphClientID is the Azure app registration client ID.
GraphClientID string
// GraphClientSecret is the Azure app registration client secret.
GraphClientSecret string
// GraphFromAddress is the shared mailbox address to send emails from.
GraphFromAddress string
// GraphRecipients is a comma-separated list of email addresses to notify.
GraphRecipients string
// RecordingAPIKey is the secret key for external recording control via REST API.
RecordingAPIKey string
// RecordingMaxDurationMinutes is the maximum allowed duration for on-demand recordings.
RecordingMaxDurationMinutes int
// Streams lists configured stream destinations.
Streams []types.Stream
// Recorders lists configured recording destinations.
Recorders []types.Recorder
}
Snapshot is a point-in-time copy of configuration values.
func (*Snapshot) HasGraph ¶ added in v0.5.0
HasGraph reports whether Microsoft Graph email notifications are configured.
func (*Snapshot) HasWebhook ¶ added in v0.2.3
HasWebhook reports whether a webhook URL is configured.
func (*Snapshot) HasZabbixSilence ¶ added in v0.8.0
HasZabbixSilence reports whether Zabbix silence alerting is configured.
func (*Snapshot) HasZabbixUpload ¶ added in v0.8.0
HasZabbixUpload reports whether Zabbix upload alerting is configured.
type StreamingConfig ¶ added in v0.6.0
type StreamingConfig struct {
// Streams lists the configured stream destinations.
Streams []types.Stream `json:"streams"`
}
StreamingConfig holds stream configuration.
type SystemConfig ¶ added in v0.6.0
type SystemConfig struct {
// FFmpegPath is the path to the FFmpeg binary, or empty to search PATH.
FFmpegPath string `json:"ffmpeg_path"`
// Port is the HTTP server port to listen on.
Port int `json:"port"`
// Username is the web interface login username.
Username string `json:"username"`
// Password is the web interface login password.
Password string `json:"password"` //nolint:gosec // G117: intentional config field for web UI auth
}
SystemConfig holds system-level configuration.
type WebConfig ¶ added in v0.2.0
type WebConfig struct {
// StationName is the station display name shown in the web UI header.
StationName string `json:"station_name"`
// ColorLight is the accent color for light theme in hex format (#RRGGBB).
ColorLight string `json:"color_light"`
// ColorDark is the accent color for dark theme in hex format (#RRGGBB).
ColorDark string `json:"color_dark"`
}
WebConfig holds web UI branding settings.
type WebhookConfig ¶ added in v0.6.0
type WebhookConfig struct {
// URL is the endpoint to POST silence alerts to.
URL string `json:"url"`
// Events controls which silence events trigger webhook notifications.
Events types.EventSubscriptions `json:"events"`
}
WebhookConfig holds webhook notification settings.