Rob Watson 266a9307d2 fix(config): ensure log file path is set
Fix a bug introduced in 6952516 which led to the app being unable to
start if logging was enabled but no explicit path was set. In this case,
the expected behaviour is to fallback to a log file in the XDG file
hierarchy, but this was lost due to broken config file defaults
handling.

This commit separates the behaviour when setting defaults when reading
an existing configuration, from those set when creating a brand new
configuration.
2025-04-04 20:49:05 +02:00

42 lines
1019 B
Go

package config
import "cmp"
// Destination holds the configuration for a destination.
type Destination struct {
Name string `yaml:"name"`
URL string `yaml:"url"`
}
// LogFile holds the configuration for the log file.
type LogFile struct {
Enabled bool `yaml:"enabled"`
Path string `yaml:"path,omitempty"`
defaultPath string
}
// GetPath returns the path to the log file. If the path is not set, it
// returns the default log path.
func (l LogFile) GetPath() string {
return cmp.Or(l.Path, l.defaultPath)
}
// RTMPSource holds the configuration for the RTMP source.
type RTMPSource struct {
Enabled bool `yaml:"enabled"`
StreamKey string `yaml:"streamkey,omitempty"`
}
// Sources holds the configuration for the sources.
type Sources struct {
RTMP RTMPSource `yaml:"rtmp"`
}
// Config holds the configuration for the application.
type Config struct {
LogFile LogFile `yaml:"logfile"`
Sources Sources `yaml:"sources"`
Destinations []Destination `yaml:"destinations"`
}